Android 将字节数组转换为Base64将创建空的、中断的URL

Android 将字节数组转换为Base64将创建空的、中断的URL,android,ruby-on-rails,base64,android-volley,Android,Ruby On Rails,Base64,Android Volley,在android中,我有一个参数,它是转换为字节数组的天数列表,然后Base64被传递到URL中的Web服务,如下所示: try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); // Saving the days selected (but also allowing none) oos.writeO

在android中,我有一个参数,它是转换为字节数组的天数列表,然后Base64被传递到URL中的Web服务,如下所示:

try {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  ObjectOutputStream oos = new ObjectOutputStream(bos);

  // Saving the days selected (but also allowing none)
  oos.writeObject(event.getChosenDays());
  buff = bos.toByteArray();
  encoddedDaysString = Base64.encodeToString(buff, Base64.DEFAULT);

} catch (Exception e) {
}

String CreateEvent = "http://" + Global.getFeastOnline()
  + "/createEvent" + "/"
  + "0" + "/"
  + "-1" + "/"
  + "-1" + "/"
  + event.getAlarmActive().toString() + "/"
  + "0" + "/"
  + event.getAlarmTimeString() + "/"
  + encoddedDaysString + "/"
  + "0" + "/"   // Should not pass tone to path
  + event.getVibrate().toString() + "/"


  + event.getAlarmName() + "/"
  + event.getAlarmDateString()
  + ".json";
但是,在执行GET请求时,它会出错。然后,检查日志,似乎转换后的字符串中添加了很大的空间,从而破坏了URL:

08-02 16:13:17.184  11663-11663/ D/Create Events Error? com.android.volley.NoConnectionError: java.net.ProtocolException: Unexpected status line: <!DOCTYPE html>
08-02 16:14:09.204  11663-11663/ V/Create Events Error? user_id: 2
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_active: true
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_time: 16:03
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_days: rO0ABXVyADNbTGNvbS5leGFtcGxlLmZlYXN0YXBwLk1haW5NZW51Lk15RXZlbnRzLkV2ZW50JERh
    eTuousH0g5N2ggIAAHhwAAAAAA==
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_tone: 0
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_vibrate: true
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_name: Event Clock
08-02 16:14:09.204  11663-11663/ V/Create Events Error? event_date: 2015-08-03
08-02 16:14:09.204  11663-11663/ V/Create Events Error? createEven: http://(IPADDRESS):3000/createEvent/0/-1/-1/true/0/16:03/rO0ABXVyADNbTGNvbS5leGFtcGxlLmZlYXN0YXBwLk1haW5NZW51Lk15RXZlbnRzLkV2ZW50JERh
    eTuousH0g5N2ggIAAHhwAAAAAA==
    /0/true/Event Clock/2015-08-03.json
08-02 16:13:17.184 11663-11663/D/创建事件错误?com.android.volley.NoConnectionError:java.net.ProtocolException:意外状态行:
08-02 16:14:09.204 11663-11663/V/创建事件错误?用户识别码:2
08-02 16:14:09.204 11663-11663/V/创建事件错误?活动事件:真
08-02 16:14:09.204 11663-11663/V/创建事件错误?活动时间:16:03
08-02 16:14:09.204 11663-11663/V/创建事件错误?事件天数:RO0ABxVYADNBTGNVBS5LEGFTCGCXLLMZLYXN0YXBWLK1HAW5NZW51LK15RZLBNRZLKV2ZW50JERH
Etuoush0G5N2ggiaahwaaaaaa==
08-02 16:14:09.204 11663-11663/V/创建事件错误?事件提示音:0
08-02 16:14:09.204 11663-11663/V/创建事件错误?事件_振动:真
08-02 16:14:09.204 11663-11663/V/创建事件错误?事件名称:事件时钟
08-02 16:14:09.204 11663-11663/V/创建事件错误?活动日期:2015-08-03
08-02 16:14:09.204 11663-11663/V/创建事件错误?create偶数:http://(IPADDRESS):3000/createEvent/0/-1/-1/true/0/16:03/rO0ABXVyADNbTGNvbS5leGFtcGxlLmZlYXN0YXBwLk1haW5NZW51Lk15RXZlbnRzLkV2ZW50JERh
Etuoush0G5N2ggiaahwaaaaaa==
/0/true/Event Clock/2015-08-03.json
我已经在浏览器中测试了删除此空间的方法,web服务一切正常


如何在不破坏Base64转换有效性的情况下删除此空间?

我认为您应该使用
URL\u SAFE
模式而不是“DEFAULT”模式来编码字节数组。 根据:

URL\u-SAFE

Encoder/decoder flag bit to indicate using the "URL and filename safe" variant of Base64 (see RFC 3548 section 4) where - and _ are used in place of + and /. 

我认为你应该使用
URL\u SAFE
模式而不是'DEFAULT'模式来编码你的字节数组。 根据:

URL\u-SAFE

Encoder/decoder flag bit to indicate using the "URL and filename safe" variant of Base64 (see RFC 3548 section 4) where - and _ are used in place of + and /. 

添加
URL\u SAFE
并没有阻止包含如此大的间隙/空间。最后我所做的只是:
.replaceAll(“\\s+”,”)
添加的
URL\u SAFE
没有阻止包含如此大的间隙/空间。我最后做的只是:
.replaceAll(“\\s+”,”)
from