android httprequest java.net.UnknownHostException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3557996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android httprequest java.net.UnknownHostException
提问by Alex Poke
I want to make a http request with android.
我想用android发出http请求。
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.
我在清单文件中设置了 Internet 权限。
I keep getting java.net.UnknownHostException: www.google.com
我不断得到 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.
我的最终目的 ios 能够调用 Web 服务。所以,我最初尝试了 ksoap2 库和正确的 url 并得到了相同的结果。
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
顺便说一句,我正在使用 mac 雪豹 eclipse 和 android 2.2 作为设置
thanks
谢谢
regards
问候
采纳答案by BenTobin
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.
我的模拟器出现问题,网络图标显示我没有服务,而且我无法连接到 Internet。通常,重新启动模拟器修复它。有一次,我不得不创建一个新的模拟器设备。
Do check for clues in the emulator/device logs. You can view them in Eclipse using the LogCat view in the DDMS perspective.
检查模拟器/设备日志中的线索。您可以使用 DDMS 透视图中的 LogCat 视图在 Eclipse 中查看它们。
回答by Yoni Samlan
Check the emulator log messages. There's a good chance you just aren't asking for the INTERNET permissionin your app manifest.
检查模拟器日志消息。很有可能您只是没有在应用程序清单中请求INTERNET 权限。
回答by ja928
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.
本托宾的回答向我指出了我遗漏的东西。我已多次重新启动模拟器无济于事,但注意到模拟器的 Wi-fi 指示器显示为 0 条。我进入设置,关闭然后打开 Wi-fi 模式,然后打开飞行模式然后关闭。这为我解决了它。我的酒吧回来了。
回答by AnDx
Delete you AVD recreate new AVD and restart the eclipse
删除您的 AVD 重新创建新的 AVD 并重新启动 eclipse
回答by mr.boyfox
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.
如果您在清单文件中有权访问 Internet,并且 WiFi 已连接,那么通过 WiFi、以太网从您的计算机共享 Internet 可能会出现问题。尝试在计算机上重新启动互联网共享。可以然后将被修复。
回答by Pratik Butani
Restart your wifi
connection if you are testing on device, its work for me.
wifi
如果您在设备上进行测试,请重新启动连接,这对我有用。