【发布时间】:2010-11-02 20:01:36
【问题描述】:
我正在尝试使用以下方法从 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 权限。
我正在使用 eclipse 进行开发。
我看到它提到我可能需要配置代理,但由于我正在调用的 Web 服务位于端口 80 上,这应该没关系吗?我可以用浏览器调用该方法。
有什么想法吗?
【问题讨论】:
-
除非您的设备位于代理服务器后面,否则代理设置无关紧要。
-
我就是这么想的。我仍然无法正常工作。