mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
d2e66a1ca2
commit
c2262bc40e
@ -85,7 +85,7 @@ public class CharSequenceResource implements Resource, Serializable {
|
||||
|
||||
@Override
|
||||
public byte[] readBytes() throws IORuntimeException {
|
||||
return this.data.toString().getBytes(this.charset);
|
||||
return StrUtil.bytes(this.data, this.charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
35
hutool-http/src/main/java/cn/hutool/http/client/body/StringBody.java
Executable file
35
hutool-http/src/main/java/cn/hutool/http/client/body/StringBody.java
Executable file
@ -0,0 +1,35 @@
|
||||
package cn.hutool.http.client.body;
|
||||
|
||||
import cn.hutool.core.io.resource.StringResource;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* String类型的body,一般用于Rest请求的请求体,如JSON或XML
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class StringBody extends ResourceBody {
|
||||
|
||||
/**
|
||||
* 构造,根据body内容类型,自动识别Content-Type
|
||||
*
|
||||
* @param body Body内容
|
||||
* @param charset 自定义编码
|
||||
*/
|
||||
public StringBody(final String body, final Charset charset) {
|
||||
this(body, HttpUtil.getContentTypeByRequestBody(body), charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param body Body内容
|
||||
* @param contentType 自定义Content-Type
|
||||
* @param charset 自定义编码
|
||||
*/
|
||||
public StringBody(final String body, final String contentType, final Charset charset) {
|
||||
super(new StringResource(body, contentType, charset));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user