public class HttpClientUtil extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
getContent(org.apache.http.HttpResponse res,
String encoding) |
static String |
httpPost(String url,
Map<String,String> params,
String encoding) |
static String |
httpPost(String url,
Map<String,String> params,
String encoding,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持重试
|
static String |
httpPostBody(String uri,
Map<String,String> headers,
Map<String,String> body) |
static String |
httpPostBodyRetries(String uri,
Map<String,String> headers,
Map<String,String> body,
int maxRetries,
long initialRetryDelayMs)
Send HTTP POST request with retry mechanism
|
static String |
httpPostData(String host,
String uri,
String authorization,
String data) |
static String |
httpPostData(String host,
String uri,
String authorization,
String data,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持授权头,支持重试
|
static void |
main(String[] args) |
static String |
postFile(File file,
String url,
String partName) |
static String |
sendDeleteRequestByJava(String reqURL) |
static String |
sendDeleteRequestByJava(String reqURL,
int maxRetries,
long retryDelayMs)
发送HTTP_DELETE请求,支持重试
|
static String |
sendGetRequest(String reqURL,
String decodeCharset) |
static String |
sendGetRequest(String reqURL,
String decodeCharset,
int maxRetries,
long retryDelayMs)
发送HTTP_GET请求,支持重试
|
static Object |
sendGetRequest(String reqURL,
String decodeCharset,
Map<String,String> param,
HashMap<String,String> headers,
boolean isFile,
String filePath) |
static Object |
sendGetRequest(String reqURL,
String decodeCharset,
Map<String,String> param,
HashMap<String,String> headers,
boolean isFile,
String filePath,
int maxRetries,
long retryDelayMs)
Send HTTP GET request with retry mechanism
|
static InputStream |
sendGetRequest(String reqURL,
String decodeCharset,
String param,
HashMap<String,String> headers) |
static InputStream |
sendGetRequest(String reqURL,
String decodeCharset,
String param,
HashMap<String,String> headers,
int maxRetries,
long retryDelayMs)
Send HTTP GET request with retry mechanism
|
static String |
sendGetSqSLRequest(String reqURL,
String encodeCharset,
String decodeCharset)
发送HTTPS_GET请求
// * @see 该方法会自动关闭连接,释放资源
// * @see 该方法会自动对
params中的[中文][|][ ]等特殊字符进行
URLEncoder.encode(string,encodeCharset) |
static String |
sendGetSqSLRequest(String reqURL,
String encodeCharset,
String decodeCharset,
int maxRetries,
long retryDelayMs)
发送HTTPS_GET请求,支持重试
|
static String |
sendPostRequest(String reqURL,
Map<String,String> params,
String encodeCharset,
String decodeCharset) |
static String |
sendPostRequest(String reqURL,
Map<String,String> params,
String encodeCharset,
String decodeCharset,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持重试
|
static ResponseVO |
sendPostRequest(String reqURL,
String sendData) |
static String |
sendPostRequest(String reqURL,
String sendData,
boolean isEncoder) |
static String |
sendPostRequest(String reqURL,
String sendData,
boolean isEncoder,
int maxRetries,
long retryDelayMs) |
static String |
sendPostRequest(String reqURL,
String sendData,
boolean isEncoder,
String encodeCharset,
String decodeCharset)
发送HTTP_POST请求
|
static String |
sendPostRequest(String reqURL,
String sendData,
boolean isEncoder,
String encodeCharset,
String decodeCharset,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持重试
|
static ResponseVO |
sendPostRequest(String reqURL,
String sendData,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持重试
|
static String |
sendPostRequest(String reqURL,
String sendData,
Map<String,Object> headers) |
static String |
sendPostRequest(String reqURL,
String sendData,
Map<String,Object> headers,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持自定义请求头,支持重试
|
static String |
sendPostRequestByJava(String reqURL,
Map<String,String> params)
发送HTTP_POST请求
|
static String |
sendPostRequestByJava(String reqURL,
Map<String,String> params,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求
|
static String |
sendPostRequestByJava(String reqURL,
String sendData)
发送HTTP_POST请求
|
static String |
sendPostRequestByJava(String reqURL,
String sendData,
int maxRetries,
long retryDelayMs)
Send HTTP POST request with retry mechanism
|
static byte[] |
sendPostRequestByJavaByte(String reqURL,
String sendData)
发送HTTP_POST请求
|
static byte[] |
sendPostRequestByJavaByte(String reqURL,
String sendData,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持重试,返回字节数组
|
static String |
sendPostRequestByJavaByteSetHeader(String reqURL,
String sendData,
String contentType,
String authorization) |
static String |
sendPostRequestByJavaByteSetHeader(String reqURL,
String sendData,
String contentType,
String authorization,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持自定义请求头,支持重试
|
static String |
sendPostRequestByJavaSetHeader(String reqURL,
String sendData,
String contentType,
String authorization) |
static String |
sendPostRequestByJavaSetHeader(String reqURL,
String sendData,
String contentType,
String authorization,
int maxRetries,
long retryDelayMs)
发送HTTP_POST请求,支持自定义请求头,支持重试
|
static String |
sendPostSSLRequest(String reqURL,
Map<String,String> params) |
static String |
sendPostSSLRequest(String reqURL,
Map<String,String> params,
int maxRetries,
long retryDelayMs) |
static String |
sendPostSSLRequest(String reqURL,
Map<String,String> params,
String encodeCharset,
String decodeCharset)
发送HTTPS_POST请求
|
static String |
sendPostSSLRequest(String reqURL,
Map<String,String> params,
String encodeCharset,
String decodeCharset,
int maxRetries,
long retryDelayMs)
发送HTTPS_POST请求,支持重试
|
static String |
sendPutRequestByJava(String reqURL,
String sendData)
发送HTTP_PUT请求
|
static String |
sendPutRequestByJava(String reqURL,
String sendData,
int maxRetries,
long retryDelayMs)
发送HTTP_PUT请求,支持重试
|
static String |
sslPost(String url,
String data,
String certPath,
String pwd) |
static String |
sslPost(String url,
String data,
String certPath,
String pwd,
int maxRetries,
long retryDelayMs)
发送HTTPS POST请求,支持证书认证,支持重试
|
public static InputStream sendGetRequest(String reqURL, String decodeCharset, String param, HashMap<String,String> headers)
public static InputStream sendGetRequest(String reqURL, String decodeCharset, String param, HashMap<String,String> headers, int maxRetries, long retryDelayMs)
reqURL - Request URLdecodeCharset - Character set for decoding responseparam - Request parameterheaders - Request headersmaxRetries - Maximum retry attemptsretryDelayMs - Retry delay in millisecondspublic static Object sendGetRequest(String reqURL, String decodeCharset, Map<String,String> param, HashMap<String,String> headers, boolean isFile, String filePath) throws Exception
Exceptionpublic static Object sendGetRequest(String reqURL, String decodeCharset, Map<String,String> param, HashMap<String,String> headers, boolean isFile, String filePath, int maxRetries, long retryDelayMs)
reqURL - 请求地址decodeCharset - 解码字符集param - 请求参数headers - 请求头isFile - 是否保存为文件filePath - 文件保存路径maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendGetRequest(String reqURL, String decodeCharset, int maxRetries, long retryDelayMs)
reqURL - 请求地址decodeCharset - 解码字符集maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String httpPost(String url, Map<String,String> params, String encoding) throws Exception
Exceptionpublic static String httpPost(String url, Map<String,String> params, String encoding, int maxRetries, long retryDelayMs) throws Exception
url - 请求地址params - 请求参数encoding - 编码字符集maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)Exception - 请求异常public static String getContent(org.apache.http.HttpResponse res, String encoding) throws Exception
Exceptionpublic static String sendPostRequest(String reqURL, String sendData, boolean isEncoder)
public static String sendPostRequest(String reqURL, String sendData, boolean isEncoder, int maxRetries, long retryDelayMs)
public static String sendPostRequest(String reqURL, String sendData, boolean isEncoder, String encodeCharset, String decodeCharset)
reqURL - 请求地址sendData - 请求参数,若有多个参数则应拼接成param11=value11¶m22=value22¶m33=value33的形式后,
传入该参数中isEncoder - 请求数据是否需要encodeCharset编码,true为需要encodeCharset - 编码字符集,编码请求数据时用之,其为null时默认采用UTF-8解码decodeCharset - 解码字符集,解析响应数据时用之,其为null时默认采用UTF-8解码该方法会自动关闭连接,释放资源,
当isEncoder=true时,其会自动对sendData中的[中文][|][
]等特殊字符进行URLEncoder.encode(string,encodeCharset)public static String sendPostRequest(String reqURL, String sendData, boolean isEncoder, String encodeCharset, String decodeCharset, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 请求参数isEncoder - 请求数据是否需要编码encodeCharset - 编码字符集decodeCharset - 解码字符集maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPostRequest(String reqURL, Map<String,String> params, String encodeCharset, String decodeCharset)
public static String sendPostRequest(String reqURL, Map<String,String> params, String encodeCharset, String decodeCharset, int maxRetries, long retryDelayMs)
reqURL - 请求地址params - 请求参数encodeCharset - 编码字符集decodeCharset - 解码字符集maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPostSSLRequest(String reqURL, Map<String,String> params)
public static String sendPostSSLRequest(String reqURL, Map<String,String> params, int maxRetries, long retryDelayMs)
public static String sendPostSSLRequest(String reqURL, Map<String,String> params, String encodeCharset, String decodeCharset)
reqURL - 请求地址params - 请求参数encodeCharset - 编码字符集,编码请求数据时用之,其为null时默认采用UTF-8解码decodeCharset - 解码字符集,解析响应数据时用之,其为null时默认采用UTF-8解码该方法会自动关闭连接,释放资源,
]等特殊字符进行
URLEncoder.encode(string,encodeCharset)public static String sendPostSSLRequest(String reqURL, Map<String,String> params, String encodeCharset, String decodeCharset, int maxRetries, long retryDelayMs)
reqURL - 请求地址params - 请求参数encodeCharset - 编码字符集decodeCharset - 解码字符集maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPostRequestByJava(String reqURL, Map<String,String> params)
reqURL - 请求地址params - 发送到远程主机的正文数据,其数据类型为java.util.Map"SUCCESS`200""Failed`500"若发送的params中含有中文,记得按照双方约定的字符集将中文
URLEncoder.encode(string,encodeCharset),
本方法默认的连接超时时间为30秒,默认的读取超时时间为30秒public static String sendPostRequestByJava(String reqURL, Map<String,String> params, int maxRetries, long retryDelayMs)
reqURL - 请求地址params - 发送到远程主机的正文数据,其数据类型为java.util.Map"SUCCESS`200""Failed`500"若发送的params中含有中文,记得按照双方约定的字符集将中文
URLEncoder.encode(string,encodeCharset),
本方法默认的连接超时时间为30秒,默认的读取超时时间为30秒public static String sendPostRequestByJava(String reqURL, String sendData)
reqURL - 请求地址sendData - 发送到远程主机的正文数据"SUCCESS`200""Failed`500"若发送的sendData中含有中文,记得按照双方约定的字符集将中文
URLEncoder.encode(string,encodeCharset),
本方法默认的连接超时时间为30秒,默认的读取超时时间为30秒public static String sendPostRequestByJava(String reqURL, String sendData, int maxRetries, long retryDelayMs)
reqURL - Request URLsendData - Data to send to remote hostmaxRetries - Maximum retry attemptsretryDelayMs - Retry delay in millisecondspublic static byte[] sendPostRequestByJavaByte(String reqURL, String sendData)
reqURL - 请求地址sendData - 发送到远程主机的正文数据"SUCCESS`200""Failed`500"若发送的sendData中含有中文,记得按照双方约定的字符集将中文
URLEncoder.encode(string,encodeCharset),
本方法默认的连接超时时间为30秒,默认的读取超时时间为30秒public static byte[] sendPostRequestByJavaByte(String reqURL, String sendData, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 发送到远程主机的正文数据maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static ResponseVO sendPostRequest(String reqURL, String sendData)
public static ResponseVO sendPostRequest(String reqURL, String sendData, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 发送到远程主机的正文数据maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPutRequestByJava(String reqURL, String sendData)
reqURL - 请求地址sendData - 发送到远程主机的正文数据"SUCCESS`200""Failed`500"若发送的sendData中含有中文,记得按照双方约定的字符集将中文
URLEncoder.encode(string,encodeCharset),
本方法默认的连接超时时间为30秒,默认的读取超时时间为30秒public static String sendPutRequestByJava(String reqURL, String sendData, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 发送到远程主机的正文数据maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendDeleteRequestByJava(String reqURL, int maxRetries, long retryDelayMs)
reqURL - 请求地址maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendGetSqSLRequest(String reqURL, String encodeCharset, String decodeCharset)
params中的[中文][|][ ]等特殊字符进行
URLEncoder.encode(string,encodeCharset)reqURL - 请求地址
// * @param params
请求参数encodeCharset - 编码字符集,编码请求数据时用之,其为null时默认采用UTF-8解码decodeCharset - 解码字符集,解析响应数据时用之,其为null时默认采用UTF-8解码public static String sendGetSqSLRequest(String reqURL, String encodeCharset, String decodeCharset, int maxRetries, long retryDelayMs)
reqURL - 请求地址encodeCharset - 编码字符集decodeCharset - 解码字符集maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPostRequestByJavaSetHeader(String reqURL, String sendData, String contentType, String authorization)
public static String sendPostRequestByJavaSetHeader(String reqURL, String sendData, String contentType, String authorization, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 发送到远程主机的正文数据contentType - 内容类型authorization - 授权信息maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPostRequestByJavaByteSetHeader(String reqURL, String sendData, String contentType, String authorization)
public static String sendPostRequestByJavaByteSetHeader(String reqURL, String sendData, String contentType, String authorization, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 发送到远程主机的正文数据contentType - 内容类型authorization - 授权信息maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String sendPostRequest(String reqURL, String sendData, Map<String,Object> headers)
public static String sendPostRequest(String reqURL, String sendData, Map<String,Object> headers, int maxRetries, long retryDelayMs)
reqURL - 请求地址sendData - 发送到远程主机的正文数据headers - 自定义请求头maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String httpPostData(String host, String uri, String authorization, String data)
uri - host - authorization - public static String httpPostData(String host, String uri, String authorization, String data, int maxRetries, long retryDelayMs)
host - 主机地址uri - 请求URIauthorization - 授权信息data - 发送到远程主机的正文数据maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)public static String httpPostBody(String uri, Map<String,String> headers, Map<String,String> body)
uri - headers - body - public static String httpPostBodyRetries(String uri, Map<String,String> headers, Map<String,String> body, int maxRetries, long initialRetryDelayMs)
uri - Request URLheaders - Request headersbody - Request body parametersmaxRetries - Maximum retry attemptsinitialRetryDelayMs - Initial retry delay in millisecondspublic static String sslPost(String url, String data, String certPath, String pwd, int maxRetries, long retryDelayMs)
url - 请求地址data - 发送到远程主机的正文数据certPath - 证书路径pwd - 证书密码maxRetries - 最大重试次数retryDelayMs - 重试延迟(毫秒)Copyright © 2025. All rights reserved.