Skip to content

Commit 17710af

Browse files
ChenJiaXin520binarywang
authored andcommitted
🎨 修复发送文件上传请求时Content-Type没有boundary的问题
1 parent 2f5e8b9 commit 17710af

File tree

3 files changed

+0
-6
lines changed

3 files changed

+0
-6
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material, WxTyp
5858
multipartEntityBuilder.addPart("description",
5959
new StringBody(WxGsonBuilder.create().toJson(form), ContentType.create("text/plain", Consts.UTF_8)));
6060
}
61-
6261
httpPost.setEntity(multipartEntityBuilder.build());
63-
//手动设置的Content-Type请求头没有boundary,是一个非标准的文件上传请求头,虽然微信提供了对这类非标准请求的支持,但如果请求需要先经过我们的tomcat server,那么都会报错:the request was rejected because no multipart boundary was found
64-
//不设置Content-Type请求头,httpclient将会自动设置,值为entity的getContentType方法返回值。MultipartEntityBuilder的getContentType方法将会返回boundary
65-
//httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
6662

6763
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
6864
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/media/MediaImgUploadApacheHttpRequestExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public WxMediaImgUploadResult execute(String uri, File data, WxType wxType) thro
4747
.setMode(HttpMultipartMode.RFC6532)
4848
.build();
4949
httpPost.setEntity(entity);
50-
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
5150

5251
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
5352
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/voice/VoiceUploadApacheHttpRequestExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public Boolean execute(String uri, File data, WxType wxType) throws WxErrorExcep
4848
.setMode(HttpMultipartMode.RFC6532)
4949
.build();
5050
httpPost.setEntity(entity);
51-
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
5251

5352
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
5453
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);

0 commit comments

Comments
 (0)