java - HttpResponse response = client.execute(httpGet), the code after httpresponse doesn't run -


i've try data web /http://localhost/android_connection/gethttpget.php follow code site,http://www.thaicreate.com/mobile/android-httpget-httppost.html.

the result of "/http://localhost/android_connection/gethttpget.php" after following line :

server date/time : 2014-06-04 04:28:49 

i'm using xampp localhost.

in android programming code after >> httpresponse response = client.execute(httpget) doesn't run catching log.e. log.e("error1.1","before try"); , log.e("error1.2","before httpresponse"); appear on logcat.

i don't know how fix plz me, way i'm beginner in programming of using webserver via android application.

public class mainactivity extends activity {      @suppresslint("newapi")     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          // permission strictmode           if (android.os.build.version.sdk_int > 9) {             strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build();             strictmode.setthreadpolicy(policy);         }          final textview result = (textview) findviewbyid(r.id.result);         final button btnget = (button) findviewbyid(r.id.btnget);          btnget.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view arg0) {                 // todo auto-generated method stub                 string url = "http://localhost/android_connection/gethttpget.php";                 string resultserver  = gethttpget(url);                 result.settext(resultserver);             }         });     }      public string gethttpget(string url) {          stringbuilder str = new stringbuilder();         httpclient client = new defaulthttpclient();         httpget httpget = new httpget(url);         log.e("error1.1","before try");         try {             log.e("error1.2", "before httpresponse");             httpresponse response = client.execute(httpget);             log.e("error1.3", "end of httpresponse");             statusline statusline = response.getstatusline();             int statuscode = statusline.getstatuscode();             if (statuscode == 200) { // status ok                 httpentity entity = response.getentity();                 inputstream content = entity.getcontent();                 bufferedreader reader = new bufferedreader(new inputstreamreader(content));                 string line;                 while ((line = reader.readline()) != null) {                     str.append(line);                     log.e("error2","line : " + line);                 }             }           } catch (clientprotocolexception e) {             // todo auto-generated catch block             e.printstacktrace();         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }         return str.tostring();     } } 

the problem server url, android devices don't recognize localhost url url of machine. recommend access xamp server machine ip if working on emulator , want work local host change url 10.0.2.2. refer developer guide


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -