java - Android HTTP post to PHP workin for intranet but not working for Internet -


i have post parameter client side(android) server side(php) using http post request parameters android. tried example working in intranet(192.168.12.33) local ip of system, not working in internet(www.dillgates.pcriot.com) website. please can 1 me.

here code. working if replaced "192.168.2.3" instead of "www.dillgates.pcriot.com"

public string httppost(string param1, string param2, string file) throws jsonexception {     arraylist<namevaluepair> namevaluepairs = new  arraylist<namevaluepair>();           namevaluepairs.add(new basicnamevaluepair("param1", param1));     namevaluepairs.add(new basicnamevaluepair("param2", param2));     try     {         httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost("http://192.168.2.3/5mine/geotracker/"+file);//working         //httppost httppost = new httppost("http://www.dillgates.pcriot.com/5mine/geotracker/"+file);//not working         httppost.setentity(new urlencodedformentity(namevaluepairs));         httpresponse response = httpclient.execute(httppost);         the_string_response = convertresponsetostring(response);     }     catch(exception e)     {         toast.maketext(geotrackeractivity.this, "error " + e.getmessage(), toast.length_long).show();         system.out.println("error in http connection "+e.tostring());     } } 

here response, whatever got in log cat.

logcat error

thanks in advance..:)

may give setting using httprequest.

-> setting of manifest

add 2 line of permission before application tag

<uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.internet" /> 

-> update polic

threadpolicy mthreadpolicy = new threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(mthreadpolicy); 

-> using httpurlconnection

string para = "username=123&password=321" httpurlconnection connection = (httpurlconnection) url.openconnection(); connection.setrequestmethod("post"); connection.setrequestproperty("content-language", "en-us"); connection.setrequestproperty("content-length", integer.tostring(para.getbytes().length)); connection.setrequestproperty("content-type", "application/x-www-form-urlencoded"); connection.setusecaches(false); connection.setdoinput(true); connection.setdooutput(true);  outputstreamwriter osw = new dataoutputstream(connection.getoutputstream()); osw.writebytes(para); osw.flush();  bufferedreader mbufferedreader = new bufferedreader(new inputstreamreader(this.mconnection.getinputstream())); stringbuilder mstringbuilder = new stringbuilder(); string line = ""; while((line = mbufferedreader.readline()) != null){     mstringbuilder.append(line); } string responsestring = mstringbuilder.tostring(); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -