Skip to content

Commit bbfe3f0

Browse files
committed
修复上传文件时的乱码问题
1 parent b24c13d commit bbfe3f0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/apache/ApacheMaterialUploadRequestExecutor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
99
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
1010
import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor;
11+
import org.apache.http.Consts;
1112
import org.apache.http.HttpHost;
1213
import org.apache.http.client.config.RequestConfig;
1314
import org.apache.http.client.methods.CloseableHttpResponse;
1415
import org.apache.http.client.methods.HttpPost;
1516
import org.apache.http.entity.ContentType;
1617
import org.apache.http.entity.mime.HttpMultipartMode;
1718
import org.apache.http.entity.mime.MultipartEntityBuilder;
19+
import org.apache.http.entity.mime.content.StringBody;
1820
import org.apache.http.impl.client.CloseableHttpClient;
1921

2022
import java.io.File;
@@ -53,7 +55,8 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throw
5355
.setMode(HttpMultipartMode.RFC6532);
5456
Map<String, String> form = material.getForm();
5557
if (material.getForm() != null) {
56-
multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
58+
multipartEntityBuilder.addPart("description",
59+
new StringBody(WxGsonBuilder.create().toJson(form), ContentType.create("text/plain", Consts.UTF_8)));
5760
}
5861

5962
httpPost.setEntity(multipartEntityBuilder.build());

0 commit comments

Comments
 (0)