在URL中传递带反斜杠的日期:Android

时间:2012-07-15 15:40:13

标签: android

只是一个简单的快速问题。我想在我的HTTP请求中传递一个日期。日期格式与此22\July\2012类似。这是我试图传递的URL。 dateChat =22\July\2012

的位置
if(this.dateChat!="") {
  this.dateChat.replace("\\", "\\\\");
}
httpclient= new DefaultHttpClient();
httpget = new HttpGet("http://10.116.27.107/php/Chat/xmlManipulator.php?" +
  "action="+this.action+"&username="+this.userName+
  "&chatText="+this.chatText+"&email="+this.email+
  "&callfrom="+this.callFrom+"&dateChatToRetrieve="+this.dateChat);

logcat出现以下错误:

 07-15 20:26:40.165: E/AndroidRuntime(2000): FATAL EXCEPTION: main
 07-15 20:26:40.165: E/AndroidRuntime(2000): java.lang.IllegalArgumentException:
  Illegal character in query at index 146:
  http://10.116.27.107/php/Chat/xmlManipulator.php?action=ReturnUserAdminChats&username=You&chatText=a&email=You&callfrom=admin&dateChatToRetrieve=5\July\2012

1 个答案:

答案 0 :(得分:2)

使用URLEncoder.encode()对dateChat进行编码