为什么我不赞成使用DefaultHttpClient? [英] Why I am getting DefaultHttpClient is deprecated?
问题描述
我正在一个项目中,在该项目中我需要调用我的服务,并且我的服务将以JSON格式返回数据.而且我不需要将此JSON响应序列化为任何POJO,只需要将数据作为String取回即可.而且此应用程序对性能至关重要,因此HttpClient
必须非常快
I am working on a project in which I need to make a call to my service and my service will return the data back in JSON format. And I don't need to serialize this JSON response to any POJO, I just need to get the data back as String. And this application is very performance critical so HttpClient
has to be pretty fast
所以我决定使用Apache HttpClient,或者还有其他更好的选择吗?
So I decided to use Apache HttpClient or is there any better alternative which I can use?
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpUriRequest request = new HttpGet("some-url");
request.addHeader("Context", "some-value");
HttpResponse response = httpClient.execute(request);
String response = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
但是它抱怨The type DefaultHttpClient is deprecated
,所以也许他们有新版本的HttpClient
或通过其他方式对URL进行HttpClient调用?
But it complains that The type DefaultHttpClient is deprecated
so maybe they have new version of HttpClient
or some other way of making a HttpClient call to an URL?
有什么我想念的吗?
推荐答案
使用此:
HttpClient httpclient = HttpClientBuilder.create().build();
请参阅此stackoverflow 发布
Refer to this stackoverflow post
这篇关于为什么我不赞成使用DefaultHttpClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!