我有一个 android 应用程序,它使用HttpClient
httppost 将数据发布到 php 服务器。问题是当我从实际的 android 设备运行我的应用程序时,我总是得到错误
“发送数据错误:org.apache.http.conn.connectTimeoutException:连接/超时。
但是使用设备浏览器我可以访问服务器 url。它在模拟器中运行良好。
这是我的代码
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
Log.i("postData", response.getStatusLine().toString());
WriteFile("Response: "+response.getStatusLine().toString(), ":", ":",
":","erlog.txt");
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
WriteFile("send data Error: "+e.toString(), ":", ":", ":","erlog.txt");
}