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