Android and Apache Interactive post and get mode request source code

Source: Internet
Author: User

public class httpkit { // static string uri =  "/http 192.168.1.175:8080/married/mobileget "; static final string tag_string = " TAG ";  public static string sendget ()  {  String uri =  "HTTP/ Myandriod.ngrok.com/married/mobileget ";  url url = null;  string  result =  "";   try {   url = new url (URI);   &NBSP;LOG.I (Tag_string, uri);   httpurlconnection urlconnection =  ( httpurlconnection)  url     .openconnection ();    inputstreamreader  is = new inputstreamreader (     urlconnection.getinputstream ());    bufferedreader bufferedreader = new bufferedreader (IS);    string readline = null;   while  ((Readline = bufferedreader.readline ())  != null)  {     result += readline;   }   is.close ();    urlconnection.disconnect ();  } catch  (malformedurlexception e)  {    e.printstacktrace ();  } catch  (ioexception e)  {    E.printstacktrace (); &NBSP;&NBSP;&NBSP;LOG.E (Tag_string, e.getmessage ());   }  return  result; } public static string sendpost ()  {  HttpPost  httprequest= null;  string action= "Http://myandriod.ngrok.com/married/mobilePost";   httpresponse httpresponse;   /* Establishing HttpPost Connection */          httprequest=new httppost (action);         list  <namevaluepair> paraMs=null;        params=new arraylist<namevaluepair> ();          params.add (New basicnamevaluepair ("str1", "Hello"));         params.add (New basicnamevaluepair ("str2", "I am andriod client!!!" "));         string result=" ";         try {             //Send HTTP  request              Httprequest.setentity (New urlencodedformentity (params,http. Utf_8));              //obtained http response              httpResponse=new  Defaulthttpclient (). Execute (httprequest);              //If the status code is 200              if (Httpresponse.getstatusline (). Getstatuscode () ==200) {                  //Remove Response string                   string strresult=entityutils.tostring ( Httpresponse.getentity ());                  result = strResult;             }else{              result  =  "Traveling for work ...";             }          } catch  (exception e)  {          result =  "A business trip ...";         }         return result;         }}

Android interacts with Apache for post and get mode request source

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.