相关疑难解决方法(0)

未解决的主机异常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;
Run Code Online (Sandbox Code Playgroud)

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

我正在用eclipse开发.

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

有任何想法吗?

java rest android

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

java ×1

rest ×1