public class HttpUtil extends Object
Constructor and Description |
---|
HttpUtil() |
Modifier and Type | Method and Description |
---|---|
static ClientEngine |
createClient(String engineName)
创建客户端引擎
|
static Request |
createGet(String url)
创建Http GET请求对象
|
static Request |
createPost(String url)
创建Http POST请求对象
|
static Request |
createRequest(String url,
Method method)
创建Http请求对象
|
static SimpleServer |
createServer(int port)
创建简易的Http服务器
|
static String |
get(String urlString)
发送get请求
|
static String |
get(String urlString,
Charset customCharset)
发送get请求
|
static String |
get(String urlString,
int timeout)
发送get请求
|
static String |
get(String urlString,
Map<String,Object> paramMap)
发送get请求
|
static String |
header(Map<String,? extends Collection<String>> headers,
String name)
获取指定的Header值,如果不存在返回
null 根据RFC2616规范,header的name不区分大小写,因此首先get值,不存在则遍历匹配不区分大小写的key。 |
static boolean |
isHttp(String url)
检测是否http
|
static boolean |
isHttps(String url)
检测是否https
|
static String |
post(String urlString,
Map<String,Object> paramMap)
发送post请求
|
static String |
post(String urlString,
String body)
发送post请求
请求体body参数支持两种类型: 1. |
static String |
post(String urlString,
String body,
int timeout)
发送post请求
请求体body参数支持两种类型: 1. |
static Response |
send(Request request)
使用默认HTTP引擎,发送HTTP请求
|
static String |
toString(Request request)
打印
Request 为可读形式 |
static String |
toString(Response response)
打印
Response 为可读形式 |
static String |
urlWithForm(String url,
Map<String,Object> form,
Charset charset,
boolean isEncodeParams)
将表单数据加到URL中(用于GET表单提交)
表单的键值对会被url编码,但是url中原参数不会被编码 |
static String |
urlWithForm(String url,
String queryString,
Charset charset,
boolean isEncode)
将表单数据字符串加到URL中(用于GET表单提交)
|
static String |
urlWithFormUrlEncoded(String url,
Map<String,Object> form,
Charset charset)
将表单数据加到URL中(用于GET表单提交)
表单的键值对会被url编码,但是url中原参数不会被编码
且对form参数进行 FormUrlEncoded ,x-www-form-urlencoded模式,此模式下空格会编码为'+'
|
public static boolean isHttps(String url)
url
- URLpublic static boolean isHttp(String url)
url
- URLpublic static Request createGet(String url)
url
- 请求的URL,可以使HTTP或者HTTPSRequest
public static Request createPost(String url)
url
- 请求的URL,可以使HTTP或者HTTPSRequest
public static String get(String urlString, Charset customCharset)
urlString
- 网址customCharset
- 自定义请求字符集,如果字符集获取不到,使用此字符集public static String get(String urlString)
urlString
- 网址public static String get(String urlString, int timeout)
urlString
- 网址timeout
- 超时时长,-1表示默认超时,单位毫秒public static String get(String urlString, Map<String,Object> paramMap)
urlString
- 网址paramMap
- post表单数据public static String post(String urlString, Map<String,Object> paramMap)
urlString
- 网址paramMap
- post表单数据public static String post(String urlString, String body)
1. 标准参数,例如 a=1&b=2 这种格式 2. Rest模式,此时body需要传入一个JSON或者XML字符串,Hutool会自动绑定其对应的Content-Type
urlString
- 网址body
- post表单数据public static String post(String urlString, String body, int timeout)
1. 标准参数,例如 a=1&b=2 这种格式 2. Rest模式,此时body需要传入一个JSON或者XML字符串,Hutool会自动绑定其对应的Content-Type
urlString
- 网址body
- post表单数据timeout
- 超时时长,-1表示默认超时,单位毫秒public static Response send(Request request)
request
- HTTP请求public static String urlWithFormUrlEncoded(String url, Map<String,Object> form, Charset charset)
url
- URLform
- 表单数据charset
- 编码 null表示不encode键值对public static String urlWithForm(String url, Map<String,Object> form, Charset charset, boolean isEncodeParams)
url
- URLform
- 表单数据charset
- 编码isEncodeParams
- 是否对键和值做转义处理public static String urlWithForm(String url, String queryString, Charset charset, boolean isEncode)
url
- URLqueryString
- 表单数据字符串charset
- 编码isEncode
- 是否对键和值做转义处理public static ClientEngine createClient(String engineName)
engineName
- 引擎名称ClientEngine
public static SimpleServer createServer(int port)
port
- 端口SimpleServer
public static String toString(Response response)
Response
为可读形式response
- Response
public static String toString(Request request)
Request
为可读形式request
- Request
Copyright © 2025. All rights reserved.