Today when doing the project, you need to pass the JSON parameter to the server interface, using Apache httpclient, there was no special processing of the parameters directly submitted, the result of the run times is wrong, as follows:
06-06 10:05:40.683:w/system.err (15573): Java.lang.IllegalArgumentException:Illegal character in query at index 40:http ://xxxxx.com/detail/?info={"Type": "1", "Shopid": "F436701fd5c0423db53a8047894ca4e1", "fields": {"name": True, "tel":
True, ' scores ': true, ' intro ': true} 06-06 10:05:40.753:w/system.err (15573): at Java.net.URI.create (uri.java:727)
06-06 10:05:40.753:w/system.err (15573): at Org.apache.http.client.methods.httpget.<init> (HttpGet.java:75) 06-06 10:05:40.753:w/system.err (15573): at Com.yulore.sdktest.http.NetUtil.get (netutil.java:106) 06-06 10:05:40.777 : W/system.err (15573): at Com.yulore.sdktest.http.BaseTask.run (basetask.java:25) 06-06 10:05:40.777:w/system.err ( 15573): At Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1076) 06-06 10:05:40.777:w/ System.err (15573): at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:569) 06-06 10:05:40.777:w/system.err (15573): at Java.lang.Thread.run (thread.java:856)
Later on the Internet to find the reason for the data: HttpGet or HttpPost can not be transmitted containing "," {","} "such parameters, the need for special characters to escape, the" turn into a%22, the {turn into a%7b, the} into a%7d
Requestvo Reqvo = new Requestvo ();
Reqvo.context = Getapplicationcontext ();
StringBuffer sb = new StringBuffer ();
Sb.append ("? info={\" type\ ":" 1\ ",");
Sb.append ("\" shopid\ ": \" "+ Shopid +" \ ");
Sb.append ("\" fields\ ": {\" name\ ": true,");
Sb.append ("\" Address\ ": true,");
Sb.append ("\" tel\ ": true,");
Sb.append ("\" Scores\ ": true,");
Sb.append ("\" intro\ ": True}}");
String param = sb.tostring (). replace ("\", "%22")
. Replace ("{", "%7b"). Replace ("}", "%7d"); Special characters are escaped
Reqvo.requesturl = getString (R.STRING.DETAIL_API). concat (param);
Reqvo.jsonparser = new Shopparser ();
Basetask task = new Basetask (Getapplicationcontext (), Reqvo,
handler);
Threadpoolmanager.getinstance (). AddTask (Task);
Note: If there are spaces in the parameters, you also need to escape, otherwise there will be problems.