java - Connect to pc localhost via android phone without using emulator -


i using async task login users though php login page here java android code :

 protected string doinbackground(string... urls) {     string result = "";      for(int = 0; <= 0; ++i) {         result = this.invokepost(urls[i], this.postdata);     }      return result; }  private string invokepost(string requesturl, hashmap<string, string> postdataparams) {     string response = "";      try {         url url = new url(requesturl);         httpurlconnection e = (httpurlconnection)url.openconnection();       /*  e.setreadtimeout(15000);         e.setconnecttimeout(15000);*/         e.setrequestmethod("post");         e.setdoinput(true);         e.setdooutput(true);         outputstream os = e.getoutputstream();         bufferedwriter writer = new bufferedwriter(new outputstreamwriter(os, "utf-8"));         writer.write(this.getpostdatastring(postdataparams));         writer.flush();         writer.close();         os.close();         int responsecode = e.getresponsecode();         string line;         if(responsecode == 200) {             for(bufferedreader br = new bufferedreader(new inputstreamreader(e.getinputstream())); (line = br.readline()) != null; response = response + line) {                 ;             }         } else {             response = "";             log.d("responce code", responsecode + "");         }     } catch (exception ex) {         response ="an exception has occured" + ex.getmessage();         ex.printstacktrace();         log.d("exception",ex.tostring());     }      return response; } 

login.java :

 hashmap postdata = new hashmap();         postdata.put("username", username);         postdata.put("password", username);         backgroundworker loginworker= new backgroundworker(this,postdata);         loginworker.execute("http://192.168.43.22:8080/login.php"); 

i not using emulator though running application through nexus 5 phone , phone , pc both connected router wifi

but getting connection exception ( couldn't ping pc through nexus 5 )

how can open connection between phone , pc

get pc ip using ipconfig in cmd , use without port

loginworker.execute("http://192.168.**.**/login.php"); 

if don't work open port 80 in firewall


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo