Skip to content

你是否在写组件的时候涉及到了 HTTP🚀 请求时,各个组件的使用者所安装的 HTTP 依赖都有所不一样,为了避免这种请求请使用 switch-http🌱 吧,它能够帮使用者选择适合的请求库。👋

License

Notifications You must be signed in to change notification settings

lhccong/switch-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JDK

简介

抽取一个简单 HTTP 的通用接口,底层实现根据具体引入依赖指定。

<dependency>
  <groupId>com.cong.http</groupId>
  <artifactId>switch-http</artifactId>
  <version>1.0.0</version>
</dependency>

特点

  • 默认会按照下面的优先级自行寻找底层实现,java 11 HttpClient -> OkHttp3 -> apache HttpClient -> hutool-http
  • 也可以自行实现 com.cong.http.support.Http 接口,通过 HttpUtil.setHttp(new MyHttpImpl()) 设置进来
  • 可以配置超时时间及代理
HttpUtil.setConfig(HttpConfig.builder()
			.timeout(Constants.DEFAULT_TIMEOUT)
			.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
			.build());
SimpleHttpResponse response = HttpUtil.get("https://www.google.com");
System.out.println("code = " + response.getCode());
System.out.println("body = " + response.getBody());

TODO

About

你是否在写组件的时候涉及到了 HTTP🚀 请求时,各个组件的使用者所安装的 HTTP 依赖都有所不一样,为了避免这种请求请使用 switch-http🌱 吧,它能够帮使用者选择适合的请求库。👋

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages