How to send a string containing the% character in webservice using HttpPost in android?

I need to send a string containing% (EX: abc% xyz) to webservice using HttpPost.

I used the following logic, but I get an IllegalCharacter exception in place (%).

**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; 
+4
source share
1 answer

Try using this code when passing a value in a query string, pass it as an entity instead.

Now your url contains a link to the page without any parameters with this, and it will complete 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

+2
source

All Articles