Simple and convenient
/** * @author think * Send HTTP requests synchronously */public class Apachehttpclient {/** * @return * */Public Stri ng HttpGet (String uri) {string response=null;//response HttpClient httpclient=new defaulthttpclient (); Create HttpGet Object HttpGet httpget=new httpget (URI); HttpResponse HttpResponse; try {//Use the Execute method to send an HTTP GET request and return the HttpResponse object Httpresponse=httpclient.execute (httpget); int statusCode = Httpresponse.getstatusline (). Getstatuscode ();//Return code, if (STATUSCODE==HTTPSTATUS.SC_OK) {//Get return result response= Entityutils.tostring (Httpresponse.getentity ());} else {response = "return code:" +statuscode;}} catch (Exception e) {//TODO auto-generated catch block E.printstacktrace ();} SYSTEM.OUT.PRINTLN (response); return response;} /** * Send Request as Post * @param URL request address * @param params parameter, post must be stored with namevaluepair[] array parameters * @return * @throws Exception * * public string HttpPost (string uri,list<namevaluepair> params) throws exception{string Response=null;HttpClient httpclient=new defaulthttpclient (); HttpPost httppost=new HttpPost (URI); try {//Set HttpPost request parameter httppost.setentity (new Urlencodedformentity (params,http. Utf_8)); Use the Execute method to send an HTTP POST request and return the HttpResponse object HttpResponse httpresponse=httpclient.execute (HttpPost); int statusCode = Httpresponse.getstatusline (). Getstatuscode ();//Return code, if (STATUSCODE==HTTPSTATUS.SC_OK) {response=e Ntityutils.tostring (Httpresponse.getentity ()); System.out.println ("______________" +response); else {response = "return code:" +statuscode; System.out.println ("______________" +response);} catch (Exception e) {e.printstacktrace ();} return response;}}
Android Server Action Class