public class HttpConfig extends Object
Constructor and Description |
---|
HttpConfig() |
Modifier and Type | Method and Description |
---|---|
HttpConfig |
addRequestInterceptor(HttpInterceptor<HttpRequest> interceptor)
设置拦截器,用于在请求前重新编辑请求
|
HttpConfig |
addResponseInterceptor(HttpInterceptor<HttpResponse> interceptor)
设置拦截器,用于在请求前重新编辑请求
|
static HttpConfig |
create()
创建默认Http配置信息
|
HttpConfig |
disableCache()
禁用缓存
|
HttpConfig |
setBlockSize(int blockSize)
采用流方式上传数据,无需本地缓存数据。
|
HttpConfig |
setConnectionTimeout(int milliseconds)
设置连接超时,单位:毫秒
|
HttpConfig |
setDecodeUrl(boolean decodeUrl)
设置是否忽略解码URL,包括URL中的Path部分和Param部分。
|
HttpConfig |
setFollowRedirectsCookie(boolean followRedirectsCookie)
自动重定向时是否处理cookie
|
HttpConfig |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
设置域名验证器
只针对HTTPS请求,如果不设置,不做验证,所有域名被信任 |
HttpConfig |
setHttpProxy(String host,
int port)
设置Http代理
|
HttpConfig |
setIgnoreEOFError(boolean ignoreEOFError)
设置是否忽略响应读取时可能的EOF异常。
|
HttpConfig |
setInterceptorOnRedirect(boolean interceptorOnRedirect)
重定向时是否使用拦截器
|
HttpConfig |
setMaxRedirectCount(int maxRedirectCount)
设置最大重定向次数
如果次数小于1则表示不重定向,大于等于1表示打开重定向 |
HttpConfig |
setProxy(Proxy proxy)
设置代理
|
HttpConfig |
setReadTimeout(int milliseconds)
设置连接超时,单位:毫秒
|
HttpConfig |
setSSLProtocol(String protocol)
设置HTTPS安全连接协议,只针对HTTPS请求,可以使用的协议包括:
此方法调用后 setSSLSocketFactory(SSLSocketFactory) 将被覆盖。 |
HttpConfig |
setSSLSocketFactory(SSLSocketFactory ssf)
设置SSLSocketFactory
只针对HTTPS请求,如果不设置,使用默认的SSLSocketFactory 默认SSLSocketFactory为:SSLSocketFactoryBuilder.create().build(); |
HttpConfig |
timeout(int milliseconds)
设置超时,单位:毫秒
超时包括: 1. |
public static HttpConfig create()
public HttpConfig timeout(int milliseconds)
1. 连接超时 2. 读取响应超时
milliseconds
- 超时毫秒数setConnectionTimeout(int)
,
setReadTimeout(int)
public HttpConfig setConnectionTimeout(int milliseconds)
milliseconds
- 超时毫秒数public HttpConfig setReadTimeout(int milliseconds)
milliseconds
- 超时毫秒数public HttpConfig disableCache()
public HttpConfig setMaxRedirectCount(int maxRedirectCount)
maxRedirectCount
- 最大重定向次数public HttpConfig setHostnameVerifier(HostnameVerifier hostnameVerifier)
hostnameVerifier
- HostnameVerifierpublic HttpConfig setHttpProxy(String host, int port)
host
- 代理 主机port
- 代理 端口public HttpConfig setProxy(Proxy proxy)
proxy
- 代理 Proxy
public HttpConfig setSSLSocketFactory(SSLSocketFactory ssf)
ssf
- SSLScketFactorypublic HttpConfig setSSLProtocol(String protocol)
setSSLSocketFactory(SSLSocketFactory)
将被覆盖。
1. TLSv1.2 2. TLSv1.1 3. SSLv3 ...
protocol
- 协议SSLUtil.createSSLContext(String)
,
setSSLSocketFactory(SSLSocketFactory)
public HttpConfig setBlockSize(int blockSize)
blockSize
- 块大小(bytes数),0或小于0表示不设置Chuncked模式public HttpConfig setIgnoreEOFError(boolean ignoreEOFError)
ignoreEOFError
- 是否忽略响应读取时可能的EOF异常。public HttpConfig setDecodeUrl(boolean decodeUrl)
true
,则会统一解码编码后的参数,false
,则不会解码已经编码的内容,在请求时只编码需要编码的部分。decodeUrl
- 是否忽略解码URLpublic HttpConfig addRequestInterceptor(HttpInterceptor<HttpRequest> interceptor)
interceptor
- 拦截器实现public HttpConfig addResponseInterceptor(HttpInterceptor<HttpResponse> interceptor)
interceptor
- 拦截器实现public HttpConfig setInterceptorOnRedirect(boolean interceptorOnRedirect)
interceptorOnRedirect
- 重定向时是否使用拦截器public HttpConfig setFollowRedirectsCookie(boolean followRedirectsCookie)
followRedirectsCookie
- 自动重定向时是否处理cookieCopyright © 2024. All rights reserved.