【发布时间】:2011-12-01 16:20:24
【问题描述】:
我现在正在尝试将数据从 android 应用程序(带有模拟器)发送到 Web 服务器(一个 php 页面)。首先,我用模拟器尝试过这个程序,它正在工作。之后,我用电话尝试了这个程序,但发生了异常:
--> IO 异常:操作超时。
我的代码的一部分:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2:90/takeDatas.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("enlem", latitude ));
nameValuePairs.add(new BasicNameValuePair("boylam", longitude ));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
} catch (ClientProtocolException e) {
Toast.makeText(ReportLocationActivity.this, "Client protokol exception ", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(ReportLocationActivity.this, "IO exception "+e.getMessage(), Toast.LENGTH_LONG).show();
}
我希望你能帮助我。 提前致谢。
【问题讨论】:
-
您可以使用相同的 URL 从浏览器连接吗?
-
您是否在您的 android manifest 中添加了互联网连接权限?
-
我认为 android 模拟器是一个独立的虚拟机,它无法访问本地主机域。正如 Guillaurne 建议的那样,尝试从您的模拟器 Web 浏览器访问此 url 以缩小您的问题(如果正确的话是与代码无关..)
-
@Joe & Guillaume - 是的,我没有从我的模拟器浏览器连接localhost:90。这个问题我该怎么办?
标签: php android http exception