【发布时间】:2015-09-07 22:57:57
【问题描述】:
我曾经从下面的代码中获取 JSON 数据,但现在 HttpClient 已弃用,我不能再这样做了。你能帮帮我吗?
String responseString = null;
try {
HttpClient client = new DefaultHttpClient();
URI apiCall = new URI("...");
HttpGet request = new HttpGet();
request.setURI(apiCall);
HttpResponse response = client.execute(request);
responseString = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
Log.e("TAG", "some sort of problem encountered", e);
}
【问题讨论】:
-
感谢@CommonsWare 的评论,如果你写了一个答案,我会认为它是正确的。但是为什么如果我用hc.apache.org/httpcomponents-client-4.3.x/android-port.html 或developer.android.com/preview/… 编译我的gradle 我的代码不正确呢?
-
@CommonsWare:看起来你标记了另一个重复问题的重复 :-)
-
@BNK:哎呀!现在太晚了……
标签: android json httpclient