我必须使用带有来自android的参数的HTTP POST请求将一些参数从客户端(android)发布到服务器端(php)。我尝试了一个在 Intranet(192.168.12.33) 中工作的示例,这是我系统的本地 IP,但在 Internet(www.dillgates.pcriot.com) 中没有工作,这是我的网站。
这是我的代码。如果我替换“192.168.2.3”而不是“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());
}
}
这是响应,无论我在 Log cat 中得到什么。