Package | Description |
---|---|
org.dromara.hutool.http.client |
HTTP请求客户端封装,请求过程如下:
Server
^ |
| v
Request Response
^ |
| v
ClientEngine
|
org.dromara.hutool.http.client.engine |
Http客户端引擎实现
|
org.dromara.hutool.http.client.engine.jdk |
基于JDK的HttpUrlConnection封装的HTTP客户端
|
org.dromara.hutool.http.client.engine.okhttp |
OKHttp3封装
文档见:https://square.github.io/okhttp/ |
Modifier and Type | Class and Description |
---|---|
class |
ApacheHttpClientConfig
针对HttpClient5和HttpClient4的配置
|
Modifier and Type | Method and Description |
---|---|
ClientConfig |
ClientConfig.enableSSLVerify()
打开SSL验证,即使用引擎默认的SSL验证方式
|
static ClientConfig |
ClientConfig.of()
创建新的 ClientConfig
|
ClientConfig |
ClientConfig.setConnectionTimeout(int connectionTimeout)
设置连接超时,单位:毫秒
|
ClientConfig |
ClientConfig.setHttpProxy(String host,
int port)
设置Http代理
|
ClientConfig |
ClientConfig.setProxy(ProxyInfo proxy)
设置代理
|
ClientConfig |
ClientConfig.setReadTimeout(int readTimeout)
设置读取超时,单位:毫秒
|
ClientConfig |
ClientConfig.setSSLInfo(SSLInfo sslInfo)
|
ClientConfig |
ClientConfig.setTimeout(int milliseconds)
设置超时,单位:毫秒
超时包括: 1. |
ClientConfig |
ClientConfig.setUseCookieManager(boolean useCookieManager)
是否使用引擎默认的Cookie管理器,默认为true
默认情况下每个客户端维护一个自己的Cookie管理器,这个管理器用于在多次请求中记录并自动附带Cookie信息 如请求登录后,服务器返回Set-Cookie信息,Cookie管理器记录之,后续请求会自动带上这个Cookie信息,从而实现会话保持。 |
Modifier and Type | Method and Description |
---|---|
HttpDownloader |
HttpDownloader.setConfig(ClientConfig config)
设置配置
|
Modifier and Type | Field and Description |
---|---|
protected ClientConfig |
AbstractClientEngine.config |
Modifier and Type | Method and Description |
---|---|
static ClientEngine |
ClientEngineFactory.createEngine(ClientConfig config)
根据用户引入的HTTP客户端引擎jar,自动创建对应的HTTP客户端引擎对象
推荐创建的引擎单例使用,此方法每次调用会返回新的引擎 对不同引擎个性化配置,使用对应的 ClientConfig 子类:
HttpClient4和HttpClient5使用ApacheHttpClientConfig
OkHttp使用OkHttpClientConfig
如果混用这些配置,则个性配置不生效 |
ClientEngine |
ClientEngine.init(ClientConfig config)
设置客户端引擎参数,如超时、代理等信息
对不同引擎个性化配置,使用对应的
ClientConfig 子类:
HttpClient4和HttpClient5使用ApacheHttpClientConfig
OkHttp使用OkHttpClientConfig
如果混用这些配置,则个性配置不生效 |
ClientEngine |
AbstractClientEngine.init(ClientConfig config) |
Constructor and Description |
---|
JdkRequestBuilder(ClientConfig config,
JdkCookieManager cookieManager)
构造
|
Modifier and Type | Class and Description |
---|---|
class |
OkHttpClientConfig
OkHttpClient 配置
|
Modifier and Type | Method and Description |
---|---|
OkHttpEngine |
OkHttpEngine.init(ClientConfig config) |
Copyright © 2025. All rights reserved.