我想發送一個查詢的url:
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 query
。可能就是空白的那部分。如何處理這個問題?
你需要編碼 url
String query = URLEncoder.encode(myEditBox.getText.toString(), "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;