我需要使用HttpPost将包含%(EX:abc%xyz)的字符串发送到webservice.
我使用了以下逻辑,但我在(%)处获得了IllegalCharacter异常.
**updatepeople.php?pilotid=1651&firstname=Nexus&lastname=Google&nickname=abc%xyz**
final int TIMEOUT_MILLISEC = 20000;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpClient httpClient = new DefaultHttpClient(httpParams);
URLEncoder.encode(url, "UTF-8");
HttpPost httpPost = new HttpPost(url);
ResponseHandler<String> resHandler = new BasicResponseHandler();
page = httpClient.execute(httpPost, resHandler);
return page;
最佳答案 在查询字符串中传递值时尝试使用此代码,而不是将此传递为实体.
现在你的网址只包含页面链接没有任何参数,它将以updatepeople.php结束
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("pilotid", "1651"));
param.add(new BasicNameValuePair("firstname", "Nexus"));
param.add(new BasicNameValuePair("lastname", "Google"));
param.add(new BasicNameValuePair("nickname", "abc%xyz"));
httpPost.setEntity(new Unew UrlEncodedFormEntity(param));
现在执行它并继续尽可能地继续