`
passion99
  • 浏览: 11152 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

http之常用客户端

    博客分类:
  • http
 
阅读更多

1、常用客户端包括httpclient、restTemplate、okHttp,

     feign是一层伪装,实现默认是httpClient,可以替换成okHttp

 

httpClient,较复杂,设计资源回收等。

apache提供的一个接口,HttpClient项目已经不维护,转移在httpcomponents组件下。

The Commons HttpClient project is now end of life, and is no longer being developed. It has been replaced by the Apache HttpComponents project in its HttpClient and HttpCore modules, which offer better performance and more flexibility.

 

 

restTemplate,spring提供,提供了较为便捷的http访问。

 

okHttp,允许复用同一个ip和端口的请求复用socket,可以降低网络连接的时间,降低服务器连接压力。高效的http客户端。

 

2、restTemplate

用户可以配置 restTemplate的实现底层,默认是java.net.HttpURLConnection,

/**
 * Create a new instance of the {@link RestTemplate} based on the given {@link ClientHttpRequestFactory}.
 * @param requestFactory the HTTP request factory to use
 * @see org.springframework.http.client.SimpleClientHttpRequestFactory
 * @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory
 */
public RestTemplate(ClientHttpRequestFactory requestFactory) {
   this();
setRequestFactory(requestFactory);
}

 可以通过定制http客户端工厂,实现改为CloseableHttpClient、okHttpClient等底层客户端实现。

 

参考资料:

https://github.com/OpenFeign/feign

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics