Rút ra một cái đơn giản HTTP thông dụng tiếp lời, tầng dưới chót thực hiện căn cứ cụ thể dẫn vào ỷ lại chỉ định.
<dependency>
<groupId>com.xkcoding.http</groupId>
<artifactId>simple-http</artifactId>
<version>1.0.5</version>
</dependency>
- Cam chịu sẽ dựa theo phía dưới ưu tiên cấp tự hành tìm kiếm tầng dưới chót thực hiện,
java 11 HttpClient -> OkHttp3 -> apache HttpClient -> hutool-http
- Cũng có thể tự hành thực hiện
com.xkcoding.http.support.Http
Tiếp lời, thông quaHttpUtil.setHttp(new MyHttpImpl())
Thiết trí tiến vào - Có thể phối trí siêu thời thời gian cập đại lý
HttpUtil.setConfig(HttpConfig.builder()
.timeout(Constants.DEFAULT_TIMEOUT)
.proxy(newProxy(Proxy.Type.HTTP,newInetSocketAddress("127.0.0.1",10080)))
.build());
SimpleHttpResponseresponse=HttpUtil.get("https:// google");
System.out.println("code ="+response.getCode());
System.out.println("body ="+response.getBody());