public class HttpClientUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static org.apache.http.client.HttpClient |
client4HTTP |
private static org.apache.http.client.HttpClient |
client4HTTPS |
| 构造器和说明 |
|---|
HttpClientUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
private static void |
close(org.apache.http.HttpResponse resp)
尝试关闭response
|
private static void |
create(HttpConfig config)
判定是否开启连接池、及url是http还是https
如果已开启连接池,则自动调用build方法,从连接池中获取client对象 否则,直接返回相应的默认client对象 |
static String |
delete(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Delete方式,请求资源或服务
|
static String |
delete(HttpConfig config)
以Delete方式,请求资源或服务
|
static OutputStream |
down(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
OutputStream out)
下载文件
|
static OutputStream |
down(HttpConfig config)
下载文件
|
private static org.apache.http.HttpResponse |
execute(HttpConfig config)
请求资源或服务
|
private static int |
fmt2Int(org.apache.http.HttpResponse resp)
转化为数字
|
static OutputStream |
fmt2Stream(org.apache.http.HttpResponse resp,
OutputStream out)
转化为流
|
private static String |
fmt2String(org.apache.http.HttpResponse resp,
String encoding)
转化为字符串
|
static String |
get(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Get方式,请求资源或服务
|
static String |
get(HttpConfig config)
以Get方式,请求资源或服务
|
private static org.apache.http.client.methods.HttpRequestBase |
getRequest(String url,
HttpMethods method)
根据请求方法名,获取request对象
|
static String |
head(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Head方式,请求资源或服务
|
static String |
head(HttpConfig config)
以Head方式,请求资源或服务
|
static String |
options(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Options方式,请求资源或服务
|
static String |
options(HttpConfig config)
以Options方式,请求资源或服务
|
static String |
patch(org.apache.http.client.HttpClient client,
String url,
Map<String,Object> parasMap,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Patch方式,请求资源或服务
|
static String |
patch(HttpConfig config)
以Patch方式,请求资源或服务
|
static String |
post(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
Map<String,Object> parasMap,
org.apache.http.protocol.HttpContext context,
String encoding)
以Post方式,请求资源或服务
|
static String |
post(HttpConfig config)
以Post方式,请求资源或服务
|
static String |
put(org.apache.http.client.HttpClient client,
String url,
Map<String,Object> parasMap,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Put方式,请求资源或服务
|
static String |
put(HttpConfig config)
以Put方式,请求资源或服务
|
static String |
send(HttpConfig config)
请求资源或服务
|
static int |
status(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
HttpMethods method)
查看资源链接情况,返回状态码
|
static int |
status(HttpConfig config)
查看资源链接情况,返回状态码
|
static String |
trace(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
String encoding)
以Trace方式,请求资源或服务
|
static String |
trace(HttpConfig config)
以Trace方式,请求资源或服务
|
static String |
upload(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context)
上传文件
|
static String |
upload(HttpConfig config)
上传文件
|
private static org.apache.http.client.HttpClient client4HTTP
private static org.apache.http.client.HttpClient client4HTTPS
private static void create(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String get(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String get(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String post(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, Map<String,Object> parasMap, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息parasMap - 请求参数context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String post(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String put(org.apache.http.client.HttpClient client, String url, Map<String,Object> parasMap, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址parasMap - 请求参数headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String put(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String delete(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String delete(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String patch(org.apache.http.client.HttpClient client, String url, Map<String,Object> parasMap, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址parasMap - 请求参数headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String patch(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String head(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String head(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String options(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String options(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String trace(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, String encoding) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作encoding - 编码HttpProcessException - http处理异常public static String trace(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static OutputStream down(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context, OutputStream out) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作out - 输出流HttpProcessException - http处理异常public static OutputStream down(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String upload(org.apache.http.client.HttpClient client, String url, org.apache.http.Header[] headers, org.apache.http.protocol.HttpContext context) throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作HttpProcessException - http处理异常public static String upload(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static int status(org.apache.http.client.HttpClient client,
String url,
org.apache.http.Header[] headers,
org.apache.http.protocol.HttpContext context,
HttpMethods method)
throws HttpProcessException
client - client对象url - 资源地址headers - 请求头信息context - http上下文,用于cookie操作HttpProcessException - http处理异常public static int status(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常public static String send(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常private static org.apache.http.HttpResponse execute(HttpConfig config) throws HttpProcessException
config - 请求参数配置HttpProcessException - http处理异常private static String fmt2String(org.apache.http.HttpResponse resp, String encoding) throws HttpProcessException
resp - 响应对象encoding - 编码HttpProcessException - http处理异常private static int fmt2Int(org.apache.http.HttpResponse resp)
throws HttpProcessException
resp - 响应对象HttpProcessException - http处理异常public static OutputStream fmt2Stream(org.apache.http.HttpResponse resp, OutputStream out) throws HttpProcessException
resp - 响应对象out - 输出流HttpProcessException - http处理异常private static org.apache.http.client.methods.HttpRequestBase getRequest(String url, HttpMethods method)
url - 资源地址method - 请求方式private static void close(org.apache.http.HttpResponse resp)
resp - HttpResponse对象Copyright © 2023. All rights reserved.