java – 未解决的主机异常Android

我正在尝试使用以下方法从 Android应用程序调用RESTful Web服务:
HttpHost target = new HttpHost("http://" + ServiceWrapper.SERVER_HOST,ServiceWrapper.SERVER_PORT);
HttpGet get = new HttpGet("/list");
String result = null;
HttpEntity entity = null;
HttpClient client = new DefaultHttpClient();
try {
    HttpResponse response = client.execute(target,get);
    entity = response.getEntity();
    result = EntityUtils.toString(entity);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    if (entity!=null)
        try {
            entity.consumeContent();
        } catch (IOException e) {}
}
return result;

我可以使用Android Emulator浏览器和我的机器浏览地址并查看xml结果.我给了我的应用程序的INTERNET许可.

我正在用日食开发

我已经看到它提到我可能需要配置一个代理,但是由于我打电话的Web服务是在80端口这应该不重要吗?我可以用浏览器调用该方法.

有任何想法吗?

解决方法

我认为问题可能在第一行:
new HttpHost("http://" + ServiceWrapper.SERVER_HOST,ServiceWrapper.SERVER_PORT);

HttpHost构造函数需要一个主机名作为其第一个参数,而不是具有“http://”前缀的主机名.

尝试删除“http://”,它应该工作:

new HttpHost(ServiceWrapper.SERVER_HOST,ServiceWrapper.SERVER_PORT);

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...