Wednesday 15 February 2012

android - getting "org.apache.http.conn.httphostconnectexception connection to http://x.x.x.x:88/mobile.php refused -



android - getting "org.apache.http.conn.httphostconnectexception connection to http://x.x.x.x:88/mobile.php refused -

i've setup mysql server using xampp, creating android app connect database. can connect without problem using mysql workbench , odbc connector off site , ably push/pull info without errors. when connecting emulated phone getting "org.apache.http.conn.httphostconnectexception connection http://x.x.x.x:88/mobile.php refused" in ddms. thought why happening???

allow net wasn't turned on... , verified, cleaned , relaunched, getting "clientprotocolexception".

public void getdata() { string result = ""; inputstream isr = null; seek { httpclient httpclient = new defaulthttpclient(); ///external ip address not local host or trying within local network httppost httpost = new httppost("http://x.x.x.x:88/mobile.php"); httpresponse response = httpclient.execute(httpost); httpentity entity = response.getentity(); isr = entity.getcontent(); } grab (exception e) { log.e("log.tag", "error in http connection " + e.tostring()); resultview.settext("could not connect database"); } seek { bufferedreader reader = new bufferedreader(new inputstreamreader( isr, "iso=8859-1"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } isr.close(); result = sb.tostring(); } grab (exception e) { log.e("log.tag", "error converting result " + e.tostring()); } seek { string s = ""; jsonarray jarray = new jsonarray(result); (int = 0; < jarray.length(); i++) { jsonobject json = jarray.getjsonobject(i); s = s + "user :" + json.getstring("username"); } resultview.settext(s); } grab (exception e) { log.e("log.tag", "error parsing info " + e.tostring()); } }

steps create work:

add net permission manifest make sure no firewall or proxy blocking server side add httppost.setheader("accept", "application/json"); after httppost declaration

php android mysql

No comments:

Post a Comment