cn.hutool.http.body.FormUrlEncodedBody Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.http.body;
import cn.hutool.core.net.url.UrlQuery;
import cn.hutool.core.util.StrUtil;
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
import java.util.Map;
/**
* application/x-www-form-urlencoded 类型请求body封装
*
* @author looly
* @since 5.7.17
*/
public class FormUrlEncodedBody extends BytesBody {
/**
* 创建 Http request body
*
* @param form 表单
* @param charset 编码
* @return FormUrlEncodedBody
*/
public static FormUrlEncodedBody create(Map form, Charset charset) {
return new FormUrlEncodedBody(form, charset);
}
/**
* 构造
*
* @param form 表单
* @param charset 编码
*/
public FormUrlEncodedBody(Map form, Charset charset) {
super(StrUtil.bytes(UrlQuery.of(form, true).build(charset), charset));
}
@Override
public String toString() {
final ByteArrayOutputStream result = new ByteArrayOutputStream();
write(result);
return result.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy