This article to share is the PHP combined with an Android client query interaction instance, the Java end is mainly in three steps to achieve: first HTTP request. Network requests related operations, step two, use the Execute method to send HTTP GET requests, and returns the HttpResponse object, step three, using the GetEntity method to live to return the result. With the need for small partners under the reference
PHP Server side:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the |
|
Java Andro:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the |
Doasktask = new Runnable () {@Override public void run () {//TODO//here HTTP request. Network request related Operations Ggname = Etname.gettex T (). toString (); Ggworkid = Etworkid.gettext (). toString (); Ggcallid = Etcallid.gettext (). toString (); String baseurl = Confiddatas.askbaseurl; String askstr = "Name=" + ggname + "&callid=" + ggcallid + "&workid=" + ggworkid; String result = null; HttpGet httpget = new HttpGet (BaseURL + askstr); The second step is to use the Execute method to send an HTTP GET request and return the HttpResponse object HttpResponse httpresponse = null; try {httpresponse = new defaulthttpclient (). Execute (httpget);} catch (Clientprotocolexception e) {//TODO auto-g Enerated Catch block E.printstacktrace (); catch (IOException e) {//TODO auto-generated catch block E.printstacktrace (); } MSG = new Message (); Bundle data = new Bundle (); if (Httpresponse.getstatusline (). Getstatuscode () = = 200) {//step three, live with the GetEntity method to return the results try {result = Entityutils.to String (Httpresponse.getentity ()); Data.putstring ("value", result); Data.putstring ("Result", "isOK"); Msg.setdata (data); Handler.sendmessage (msg); catch (ParseException e) {//E.printstacktrace ();} catch (IOException e) {//E.printstacktrace ();}} else {//Error data.putstring ("Value", ""); Data.putstring ("Result", "iserr"); Msg.setdata (data); Handler.sendmessage (msg); } } }; |
The above is the entire contents of this article, I hope you can enjoy.