1

我正在尝试发送查询网址

String url = String.format(
   "http://xxxxx/xxx/xxx&message=%s",myEditBox.getText.toString());
// Create a new HttpClient and Post Header
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httpclient.getCookieStore().addCookie(cooki);
try {
   ResponseHandler<String> responseHandler = new BasicResponseHandler();
   httpclient.getParams().setParameter("http.connection-manager.timeout", 15000);
   String response = httpclient.execute(httppost, responseHandler);

给我错误,illegal character at querywhite space大概就是这样。如何处理这个问题?

最好的祝福

4

3 回答 3

5

您需要对您的网址进行编码。

String query = URLEncoder.encode(myEditBox.getText.toString(), "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;
于 2012-11-01T08:21:55.090 回答
0

你能试一下吗

 httpclient.setRequestProperty("Accept-Charset","UTF-8");
 url="http://xxxxx/xxx/xxx&message="+URLEncoder.encode(myEditBox.getText.toString(), "UTF-8");
于 2012-11-01T08:22:17.603 回答
0

尝试 .trim() 同时从 edittext 获取值。可能是空白来自edittext,也使用“utf-8”。

见下面的代码。

String value = URLEncoder.encode(myEditBox.getText.toString().trim(), "utf-8");
String url = "http://xxxxx/xxx/xxx&message=%s" + value;
于 2012-11-01T08:31:41.977 回答