【发布时间】:2012-05-21 11:39:55
【问题描述】:
我正在尝试将 mysql 与 android 连接,但它给我一个错误。 http 连接 java.net.UnknownHostException 出错:
下面是我的代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.pherma.net84.net/admin/getAllPeopleBornAfter.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
但是 URL 工作正常。请复制并粘贴网址。
【问题讨论】:
-
您设备的互联网连接是否正常工作?您是否在 AndroidManifest 中指定了“互联网”权限?
-
去掉这一行 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
-
它现在可以工作了……我的错……没有在清单中授予网络权限