public class HttpUtil extends Object
| 构造器和说明 |
|---|
HttpUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
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 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 Response |
send(Request request)
使用默认HTTP引擎,发送HTTP请求
|
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表单提交)
|
public static boolean isHttps(String url)
url - URLpublic static boolean isHttp(String url)
url - URLpublic 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 Response send(Request request)
request - HTTP请求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 SimpleServer createServer(int port)
port - 端口SimpleServerCopyright © 2023. All rights reserved.