PHP combines an Android client to implement a query interaction instance

Source: Internet
Author: User
Tags gettext http request php server

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.