mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-18 04:15:35 +08:00
fix code
This commit is contained in:
parent
0d0727d0f9
commit
a063a2aa99
@ -173,6 +173,28 @@ public class HttpUtil {
|
|||||||
.bodyStr();
|
.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送post请求<br>
|
||||||
|
* 请求体body参数支持两种类型:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 1. 标准参数,例如 a=1&b=2 这种格式
|
||||||
|
* 2. Rest模式,此时body需要传入一个JSON或者XML字符串,Hutool会自动绑定其对应的Content-Type
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param urlString 网址
|
||||||
|
* @param body post表单数据
|
||||||
|
* @param timeout 超时时长,-1表示默认超时,单位毫秒
|
||||||
|
* @return 返回数据
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public static String post(final String urlString, final String body, final int timeout) {
|
||||||
|
// 创建自定义客户端
|
||||||
|
return ClientEngineFactory.createEngine()
|
||||||
|
.init(ClientConfig.of().setConnectionTimeout(timeout).setReadTimeout(timeout))
|
||||||
|
.send(Request.of(urlString).method(Method.POST).body(body)).bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用默认HTTP引擎,发送HTTP请求
|
* 使用默认HTTP引擎,发送HTTP请求
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user