diff --git a/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java b/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java index 5b612b5fe..40331d121 100644 --- a/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java +++ b/hutool-http/src/main/java/org/dromara/hutool/http/HttpUtil.java @@ -173,6 +173,28 @@ public class HttpUtil { .bodyStr(); } + /** + * 发送post请求
+ * 请求体body参数支持两种类型: + * + *
+	 * 1. 标准参数,例如 a=1&b=2 这种格式
+	 * 2. Rest模式,此时body需要传入一个JSON或者XML字符串,Hutool会自动绑定其对应的Content-Type
+	 * 
+ * + * @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请求 *