Module bus.http

Class Httpx

java.lang.Object
org.miaixz.bus.http.Httpx

public class Httpx extends Object
发送HTTP请求辅助类
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • Httpx

      public Httpx()
      提供返回实例的静态方法
    • Httpx

      public Httpx(X509TrustManager x509TrustManager)
      提供返回实例的静态方法
      Parameters:
      x509TrustManager - 信任管理器
    • Httpx

      public Httpx(int connTimeout, int readTimeout, int writeTimeout)
      构建一个自定义配置的 HTTP Client 类
      Parameters:
      connTimeout - 连接
      readTimeout - 读取
      writeTimeout - 输出
    • Httpx

      public Httpx(int connTimeout, int readTimeout, int writeTimeout, int maxRequests, int maxRequestsPerHost, int maxIdleConnections, int keepAliveDuration)
      构建一个自定义配置的 HTTP Client 类
      Parameters:
      connTimeout - 连接
      readTimeout - 读取
      writeTimeout - 输出
      maxRequests - 最大请求
      maxRequestsPerHost - 主机最大请求
      maxIdleConnections - 最大连接
      keepAliveDuration - 链接时长
    • Httpx

      public Httpx(DnsX dns, HttpProxy httpProxy, int connTimeout, int readTimeout, int writeTimeout, int maxRequests, int maxRequestsPerHost, int maxIdleConnections, int keepAliveDuration)
      构建一个自定义配置的 HTTP Client 类
      Parameters:
      dns - DNS 信息
      httpProxy - 代理信息
      connTimeout - 连接
      readTimeout - 读取
      writeTimeout - 输出
      maxRequests - 最大请求
      maxRequestsPerHost - 主机最大请求
      maxIdleConnections - 最大连接
      keepAliveDuration - 链接时长
    • Httpx

      public Httpx(DnsX dns, HttpProxy httpProxy, int connTimeout, int readTimeout, int writeTimeout, int maxRequests, int maxRequestsPerHost, int maxIdleConnections, int keepAliveDuration, SSLSocketFactory sslSocketFactory, X509TrustManager x509TrustManager, HostnameVerifier hostnameVerifier)
      构建一个自定义配置的 HTTP Client 类
      Parameters:
      dns - DNS 信息
      httpProxy - 代理信息
      connTimeout - 连接
      readTimeout - 读取
      writeTimeout - 输出
      maxRequests - 最大请求
      maxRequestsPerHost - 主机最大请求
      maxIdleConnections - 最大连接
      keepAliveDuration - 链接时长
      sslSocketFactory - 抽象类,扩展自SocketFactory, SSLSocket的工厂
      x509TrustManager - 证书信任管理器
      hostnameVerifier - 主机名校验信息
  • Method Details

    • get

      public static String get(String url)
      简单的 GET 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      Returns:
      the String
    • get

      public static String get(String url, String charset)
      简单的 GET 请求 使用自定义编码
      Parameters:
      url - URL地址
      charset - 自定义编码
      Returns:
      the String
    • get

      public static String get(String url, boolean isAsync)
      异步get请求,回调
      Parameters:
      url - URL地址
      isAsync - 是否异步
      Returns:
      the String
    • get

      public static String get(String url, Map<String,String> formMap)
      带查询参数 GET 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 查询参数
      Returns:
      the String
    • get

      public static void get(String url, Callback callback)
      异步处理的GET请求,自定义请求类型
      Parameters:
      url - URL地址
      callback - 回调信息
    • get

      public static String get(String url, Map<String,String> formMap, Map<String,String> headerMap)
      带查询参数 GET 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 查询参数
      headerMap - Header参数
      Returns:
      the String
    • get

      public static String get(String url, Map<String,String> formMap, Map<String,String> headerMap, String charset)
      带查询参数 GET 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 查询参数
      headerMap - Header参数
      charset - 自定义编码
      Returns:
      the String
    • post

      public static void post(String url, Map<String,String> formMap, Callback callback)
      异步处理的POST请求,自定义请求类型
      Parameters:
      url - URL地址
      formMap - 查询参数
      callback - 回调信息
    • post

      public static String post(String url)
      form 方式 POST 请求
      Parameters:
      url - URL地址 String
      Returns:
      the String
    • post

      public static String post(String url, Map<String,String> formMap)
      form 方式 POST 请求 application/x-www-form-urlencoded
      Parameters:
      url - URL地址
      formMap - 查询参数
      Returns:
      the String
    • post

      public static String post(String url, String data, String mediaType)
      带查询参数 POST 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      data - 请求数据
      mediaType - 类型
      Returns:
      the String
    • post

      public static String post(String url, Map<String,String> formMap, String mediaType)
      带查询参数 POST 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 请求数据
      mediaType - 类型
      Returns:
      the String
    • post

      public static String post(String url, Map<String,String> formMap, Map<String,String> headerMap)
      带查询参数 POST 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      Returns:
      the String
    • post

      public static String post(String url, String data, String mediaType, String charset)
      带查询参数 POST 请求 使用自定义编码
      Parameters:
      url - URL地址
      data - 请求数据
      mediaType - 类型
      charset - 自定义编码
      Returns:
      the String
    • post

      public static String post(String url, String data, Map<String,String> headerMap, String mediaType)
      带查询参数 POST 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      data - 请求数据
      headerMap - 头部数据
      mediaType - 类型
      Returns:
      the String
    • post

      public static String post(String url, Map<String,String> formMap, String mediaType, String charset)
      带查询参数 POST 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      mediaType - 类型
      charset - 自定义编码
      Returns:
      the String
    • post

      public static String post(String url, Map<String,String> formMap, Map<String,String> headerMap, String mediaType)
      带查询参数 POST 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      mediaType - 类型
      Returns:
      the String
    • post

      public static String post(String url, Map<String,String> formMap, Map<String,String> headerMap, String mediaType, String charset)
      带查询参数 POST 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      mediaType - 类型
      charset - 自定义编码
      Returns:
      the String
    • put

      public static String put(String url)
      简单的 PUT 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      Returns:
      the String
    • put

      public static String put(String url, Map<String,String> formMap)
      带查询参数 PUT 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 请求数据
      Returns:
      the String
    • put

      public static String put(String url, String data, String mediaType)
      带查询参数 PUT 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      data - 请求数据
      mediaType - 类型
      Returns:
      the String
    • put

      public static String put(String url, Map<String,String> formMap, String mediaType)
      带查询参数 PUT 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 请求数据
      mediaType - 类型
      Returns:
      the String
    • put

      public static String put(String url, Map<String,String> formMap, Map<String,String> headerMap)
      带查询参数 PUT 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      Returns:
      the String
    • put

      public static String put(String url, String data, String mediaType, String charset)
      带查询参数 PUT 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      data - 请求数据
      mediaType - 类型
      charset - 自定义编码
      Returns:
      the String
    • put

      public static String put(String url, String data, Map<String,String> headerMap, String mediaType)
      带查询参数 PUT 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      data - 请求数据
      headerMap - 头部数据
      mediaType - 类型
      Returns:
      the String
    • put

      public static String put(String url, Map<String,String> formMap, String mediaType, String charset)
      带查询参数 PUT 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      mediaType - 类型
      charset - 自定义编码
      Returns:
      the String
    • put

      public static String put(String url, Map<String,String> formMap, Map<String,String> headerMap, String mediaType)
      带查询参数 PUT 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      mediaType - 类型
      Returns:
      the String
    • put

      public static String put(String url, Map<String,String> formMap, Map<String,String> headerMap, String mediaType, String charset)
      带查询参数 PUT 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      mediaType - 类型
      charset - 自定义编码
      Returns:
      the String
    • delete

      public static String delete(String url)
      简单的 DELETE 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      Returns:
      the String
    • delete

      public static String delete(String url, Map<String,String> formMap)
      带查询参数 DELETE 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 请求数据
      Returns:
      the String
    • delete

      public static String delete(String url, Map<String,String> formMap, String charset)
      带查询参数 DELETE 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      charset - 自定义编码
      Returns:
      the String
    • delete

      public static String delete(String url, Map<String,String> formMap, Map<String,String> headerMap)
      带查询参数 DELETE 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      Returns:
      the String
    • delete

      public static String delete(String url, Map<String,String> formMap, Map<String,String> headerMap, String charset)
      带查询参数 DELETE 请求 使用自定义编码
      Parameters:
      url - URL地址
      formMap - 请求数据
      headerMap - 头部数据
      charset - 自定义编码
      Returns:
      the String
    • head

      public static String head(String url)
      简单的 HEAD 请求 使用默认编码 UTF-8
      Parameters:
      url - URL地址
      Returns:
      响应头信息,格式为字符串
    • head

      public static String head(String url, String charset)
      HEAD 请求 使用自定义编码
      Parameters:
      url - URL地址
      charset - 自定义编码
      Returns:
      响应头信息,格式为字符串
    • head

      public static String head(String url, Map<String,String> headerMap, String charset)
      带头部参数 HEAD 请求 使用自定义编码
      Parameters:
      url - URL地址
      headerMap - 头部数据
      charset - 自定义编码
      Returns:
      响应头信息,格式为字符串
    • post

      public static String post(String url, Map<String,String> formMap, List<String> list)
      表单提交带文件上传
      Parameters:
      url - 请求地址
      formMap - 请求参数
      list - 文件路径
      Returns:
      the String