类 HttpConfig

java.lang.Object
com.cdkjframework.util.network.request.HttpConfig

public class HttpConfig extends Object
http配置
  • 构造器详细资料

    • HttpConfig

      public HttpConfig()
  • 方法详细资料

    • create

      public static HttpConfig create()
      创建默认Http配置信息
      返回:
      HttpConfig
    • timeout

      public HttpConfig timeout(int milliseconds)
      设置超时,单位:毫秒
      超时包括:
       1. 连接超时
       2. 读取响应超时
       
      参数:
      milliseconds - 超时毫秒数
      返回:
      this
      另请参阅:
    • setConnectionTimeout

      public HttpConfig setConnectionTimeout(int milliseconds)
      设置连接超时,单位:毫秒
      参数:
      milliseconds - 超时毫秒数
      返回:
      this
    • setReadTimeout

      public HttpConfig setReadTimeout(int milliseconds)
      设置连接超时,单位:毫秒
      参数:
      milliseconds - 超时毫秒数
      返回:
      this
    • disableCache

      public HttpConfig disableCache()
      禁用缓存
      返回:
      this
    • setMaxRedirectCount

      public HttpConfig setMaxRedirectCount(int maxRedirectCount)
      设置最大重定向次数
      如果次数小于1则表示不重定向,大于等于1表示打开重定向
      参数:
      maxRedirectCount - 最大重定向次数
      返回:
      this
    • setHostnameVerifier

      public HttpConfig setHostnameVerifier(HostnameVerifier hostnameVerifier)
      设置域名验证器
      只针对HTTPS请求,如果不设置,不做验证,所有域名被信任
      参数:
      hostnameVerifier - HostnameVerifier
      返回:
      this
    • setHttpProxy

      public HttpConfig setHttpProxy(String host, int port)
      设置Http代理
      参数:
      host - 代理 主机
      port - 代理 端口
      返回:
      this
    • setProxy

      public HttpConfig setProxy(Proxy proxy)
      设置代理
      参数:
      proxy - 代理 Proxy
      返回:
      this
    • setSSLSocketFactory

      public HttpConfig setSSLSocketFactory(SSLSocketFactory ssf)
      设置SSLSocketFactory
      只针对HTTPS请求,如果不设置,使用默认的SSLSocketFactory
      默认SSLSocketFactory为:SSLSocketFactoryBuilder.create().build();
      参数:
      ssf - SSLScketFactory
      返回:
      this
    • setSSLProtocol

      public HttpConfig setSSLProtocol(String protocol)
      设置HTTPS安全连接协议,只针对HTTPS请求,可以使用的协议包括:
      此方法调用后setSSLSocketFactory(SSLSocketFactory) 将被覆盖。
       1. TLSv1.2
       2. TLSv1.1
       3. SSLv3
       ...
       
      参数:
      protocol - 协议
      返回:
      this
      另请参阅:
    • setBlockSize

      public HttpConfig setBlockSize(int blockSize)
      采用流方式上传数据,无需本地缓存数据。
      HttpUrlConnection默认是将所有数据读到本地缓存,然后再发送给服务器,这样上传大文件时就会导致内存溢出。
      参数:
      blockSize - 块大小(bytes数),0或小于0表示不设置Chuncked模式
      返回:
      this
    • setIgnoreEofError

      public HttpConfig setIgnoreEofError(boolean ignoreEofError)
      设置是否忽略响应读取时可能的EOF异常。
      在Http协议中,对于Transfer-Encoding: Chunked在正常情况下末尾会写入一个Length为0的的chunk标识完整结束。
      如果服务端未遵循这个规范或响应没有正常结束,会报EOF异常,此选项用于是否忽略这个异常。
      参数:
      ignoreEofError - 是否忽略响应读取时可能的EOF异常。
      返回:
      this
      从以下版本开始:
      5.7.20
    • setDecodeUrl

      public HttpConfig setDecodeUrl(boolean decodeUrl)
      设置是否忽略解码URL,包括URL中的Path部分和Param部分。
      在构建Http请求时,用户传入的URL可能有编码后和未编码的内容混合在一起,如果此参数为true,则会统一解码编码后的参数,
      按照RFC3986规范,在发送请求时,全部编码之。如果为false,则不会解码已经编码的内容,在请求时只编码需要编码的部分。
      参数:
      decodeUrl - 是否忽略解码URL
      返回:
      this
    • setInterceptorOnRedirect

      public HttpConfig setInterceptorOnRedirect(boolean interceptorOnRedirect)
      重定向时是否使用拦截器
      参数:
      interceptorOnRedirect - 重定向时是否使用拦截器
      返回:
      this
    • setFollowRedirectsCookie

      public HttpConfig setFollowRedirectsCookie(boolean followRedirectsCookie)
      自动重定向时是否处理cookie
      参数:
      followRedirectsCookie - 自动重定向时是否处理cookie
      返回:
      this
      从以下版本开始:
      5.8.15
    • setUseDefaultContentTypeIfNull

      public HttpConfig setUseDefaultContentTypeIfNull(boolean useDefaultContentTypeIfNull)
      设置是否使用默认Content-Type,如果请求中未设置Content-Type,是否使用默认值
      参数:
      useDefaultContentTypeIfNull - 是否使用默认Content-Type
      返回:
      this
      从以下版本开始:
      5.8.33
    • setIgnoreContentLength

      public HttpConfig setIgnoreContentLength(boolean ignoreContentLength)
      设置是否忽略Content-Length,如果为true,则忽略Content-Length,自动根据响应内容计算Content-Length
      参数:
      ignoreContentLength - 是否忽略Content-Length
      返回:
      this
      从以下版本开始:
      5.8.39