/** * Tools for building communication between servers * * * */public class Httpclientadapter {private HttpClient client;private HttpRequest reque St;private httpget get;private httppost post;private httpresponse response;public HttpClientAdapter () {// Set Clientclient=new defaulthttpclient ();//Set APN information: IP portif (Stringutils.isnotblank (Globalparams.ip)) {HttpHost Host =new httphost (Globalparams.ip, Globalparams.port), Client.getparams (). Setparameter (Connroutepnames.default_proxy, host);}} /** * Send XML */public inputstream sendpostrequest (string uri, string xml) {//Use post to send xmlpost = new HttpPost (URI); try {Stri ngentity entity = new Stringentity (XML, Constantvalue.charset);p ost.setentity (entity); response = Client.execute (POST) ;//Determine the status code of the reply 200if (Response.getstatusline (). Getstatuscode () = = 200) {//Get the server reply message return response.getentity (). GetContent ();}} catch (Exception e) {e.printstacktrace ();} return null;}}
Android HttpClient network communication tool class based on XML