【发布时间】:2012-01-19 16:50:45
【问题描述】:
我现在正在尝试将数据从 android 应用程序(带有模拟器)发送到 Web 服务器(一个 php 页面)。首先,我用模拟器尝试了这个程序,它运行成功。之后,我用电话尝试了这个程序,但发生了异常:
--> IO 异常:操作超时。
我的代码的一部分:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.33: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();
}
我希望你能帮助我。 提前致谢。
【问题讨论】:
-
不,我只看到这个例外。
-
您是否检查过您的网络服务器是否正确地监听了您机器上的端口 90?
-
尝试在您的手机浏览器中访问 PHP 页面,它会加载吗?如果您的手机不在同一个网络上,则无法访问主机,因为它使用的是私有 IP 地址。
-
@molnarm- 是的,我的手机浏览器无法连接到我的 php 页面。我能做什么?
-
@MisterSquonk - 是的,我的网络服务器正在正确监听我电脑上的端口 90。 (这个程序在模拟器上运行顺利)
标签: android http exception send