1 classMytask_sendmessageextendsAsynctask<string, Void, string> {2 3 @Override4 protected voidOnPostExecute (String result) {5 Super. OnPostExecute (result);6 showresponsefromtuling (result);7 }8 9 @OverrideTen protectedstring Doinbackground (String ... arg0) { OneHttpPost request =NewHttpPost (arg0[0]); A //the HTTP header must be added to return JSON data when WebMethod is called -Request.addheader ("Content-type", "Application/json; Charset=utf-8 "); - the Try { - //Adding Parameters -Jsonobject param =NewJsonobject (); -Param.put ("Key", Constants.api_key); +Param.put ("info", arg0[1]); -httpentity entity =NewStringentity (Param.tostring (), "Utf-8"); + request.setentity (entity); A at //send a request and get feedback -HttpResponse response =Newdefaulthttpclient () - . Execute (request); - intCode =response.getstatusline (). Getstatuscode (); - if(Code = = 200) { -String result =entityutils.tostring (Response.getentity ()); in returnresult.tostring (); - } to return""; +}Catch(Exception e) { - //TODO auto-generated Catch block the e.printstacktrace (); * } $ return"";Panax Notoginseng } - the}
Android Asynchronous request