Reputation: 1071
i need to send a string that contains % (EX: abc%xyz) to webservice using HttpPost.
I used the following logic, but i am getting IllegalCharacter exception at place of (%).
**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;
Upvotes: 4
Views: 427
Reputation: 30855
Try with this code as you passing your value in query string instead this pass by this as entity.
Now your url only contain page link no any parameter with this and it will be end with 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));
now execute it and continue as you can
Upvotes: 2