android httprequest java.net.UnknownHostException
我想用android发出http请求。
使用这个:
void testHTTP()
{
HttpClient httpClient = new DefaultHttpClient();
HttpUriRequest request = new HttpPost("http://www.google.com");
try {
HttpResponse response = httpClient.execute(request);
//System.out.println("response protocol version: " + response.getProtocolVersion());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我在清单文件中设置了互联网权限。
我不断收到 java.net.UnknownHostException: www.google.com
我的最终目的 ios 能够调用 Web 服务。因此,我最初尝试了 ksoap2 库和正确的 url,并得到了相同的结果。
我怀疑我的应用程序或模拟器中有一些错误的设置。
你能给我一些关于去哪里看的指示吗?
它也将是有用的类似事情的工作示例。然后我可以检查,如果问题仍然存在,我就会知道这是我的开发设置有问题。
顺便说一句,我使用 mac 雪豹与 eclipse 和 android 2.2 作为设置,
谢谢
问候
I want to make a http request with android.
is use this:
void testHTTP()
{
HttpClient httpClient = new DefaultHttpClient();
HttpUriRequest request = new HttpPost("http://www.google.com");
try {
HttpResponse response = httpClient.execute(request);
//System.out.println("response protocol version: " + response.getProtocolVersion());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have the internet permission set in my manifest file.
I keep getting java.net.UnknownHostException: www.google.com
My final purpose ios to be able to invoke a web service. So, I initially tried the ksoap2 library and the proper url and got the same result.
I suspect I have some bad setting either in my app or in my emulator.
can you give me some pointers on where to look?
it would also bee useful a working example of something similar. then i could check and if the problem persists i would know that is my development setup at fault.
btw, i am using mac snow leopard with eclipse and android 2.2 as a setup
thanks
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
检查模拟器日志消息。很有可能您只是没有请求 INTERNET 权限您的应用程序清单。
Check the emulator log messages. There's a good chance you just aren't asking for the INTERNET permission in your app manifest.
我在使用模拟器时遇到了问题,网络图标显示我没有服务,并且无法连接到 Internet。通常,重新启动模拟器即可修复此问题。有一次,我必须创建一个新的模拟器设备。
请检查模拟器/设备日志中的线索。您可以使用 DDMS 透视图中的 LogCat 视图在 Eclipse 中查看它们。
I've had problems with the emulator where the network icon shows that I have no service, and I can't connect to the Internet. Usually, restarting the emulator fixed it. Once, I had to create a new emulator device.
Do check for clues in the emulator/device logs. You can view them in Eclipse using the LogCat view in the DDMS perspective.
本托宾的回答让我发现了我所遗漏的东西。我多次重新启动模拟器,但没有效果,但注意到模拟器的 Wi-fi 指示灯显示 0 条。我进入设置,关闭 Wi-Fi 模式然后再打开,也打开飞行模式然后关闭。这为我解决了这个问题。我的酒吧又回来了。
BenTobin's answer pointed me to something I was missing. I had restarted the emulator several times to no avail, but noticed the emulator's Wi-fi indicator was showing 0 bars. I went into settings, turned Wi-fi mode off and then on and also Airplane Mode On then off. This resolved it for me. My bars came back.
删除你的 AVD 重新创建新的 AVD 并重新启动 eclipse
Delete you AVD recreate new AVD and restart the eclipse
如果清单文件中有您访问互联网的权限,并且 WiFi 已连接,那么通过 WiFi、以太网从您的计算机共享互联网时可能会出现问题。尝试在计算机上重新启动互联网共享。然后就可以修复了。
If you have permission to access the Internet is at the manifest file and the WiFi is connected so can have problems sharing the internet from your computer via WiFi, Ethernet. Try restarting internet sharing on computer. Can then will be fixed.
如果您正在设备上进行测试,请重新启动您的
wifi
连接,这对我有用。Restart your
wifi
connection if you are testing on device, its work for me.