Version: 4.1
HttpClient HttpClient = new Defaulthttpclient ();
HttpPost HttpPost =Newhttppost (URL);//Httppost.setheader ("accept-encoding", "gzip,deflate");//indicates that the returned data is compressed in ZIP formatString Postparam = "";//the parameter contents of the request List<NameValuePair> Nvps =NewArraylist<namevaluepair>(); Nvps.add (NewBasicnamevaluepair ("Data", Postparam)); Httppost.setentity (NewUrlencodedformentity (Nvps, "Utf-8")); HttpResponse Response=Httpclient.execute (HttpPost); Httpentity Entity=response.getentity (); if(Response.getstatusline (). Getstatuscode () = = 200) {if(Entity.getcontentencoding (). toString (). Equalsignorecase ("Content-encoding:gzip") {response.setentity (NewGzipdecompressingentity (Response.getentity ()));//Unzip the zipentity =response.getentity (); } String responsecontent=entityutils.tostring (entity); System.out.println ("Responsecontent: \ n" +responsecontent); }}
- Case with no parameter name
HttpClient HttpClient =Newdefaulthttpclient (); HttpPost HttpPost=Newhttppost (URL);//Httppost.setheader ("accept-encoding", "gzip,deflate");//indicates that the returned data is compressed in ZIP format String postparam = "";//requested parameter contents stringentity paramentity = new stringentity (Postparam);//no parameter name, only parameter content httppost.setentity (paramentity); HttpResponse Response=Httpclient.execute (HttpPost); Httpentity Entity=response.getentity (); if(Response.getstatusline (). Getstatuscode () = = 200) {if(Entity.getcontentencoding (). toString (). Equalsignorecase ("Content-encoding:gzip") {response.setentity (NewGzipdecompressingentity (Response.getentity ()));//Unzip the zipentity =response.getentity (); } String responsecontent=entityutils.tostring (entity); System.out.println ("Responsecontent: \ n" +responsecontent); }}
- Class structure diagram of httpentity
HttpClient POST Request example (no parameter name and example with parameter name)