From 6fc1b7ad3aed7b29c59509ceed15b760a689081f Mon Sep 17 00:00:00 2001 From: ChenJiaXin520 <30996653+ChenJiaXin520@users.noreply.github.com> Date: Wed, 15 May 2024 23:07:57 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20#3273=20=E3=80=90=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E3=80=91=E4=BF=AE=E5=A4=8D=E5=8F=91=E9=80=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E8=AF=B7=E6=B1=82=E6=97=B6Content-T?= =?UTF-8?q?ype=E6=B2=A1=E6=9C=89boundary=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../material/MaterialUploadApacheHttpRequestExecutor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java index 053ff16cb..2d4834148 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/requestexecuter/material/MaterialUploadApacheHttpRequestExecutor.java @@ -60,7 +60,9 @@ public class MaterialUploadApacheHttpRequestExecutor extends MaterialUploadReque } httpPost.setEntity(multipartEntityBuilder.build()); - httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); + //手动设置的Content-Type请求头没有boundary,是一个非标准的文件上传请求头,虽然微信提供了对这类非标准请求的支持,但如果请求需要先经过我们的tomcat server,那么都会报错:the request was rejected because no multipart boundary was found + //不设置Content-Type请求头,httpclient将会自动设置,值为entity的getContentType方法返回值。MultipartEntityBuilder的getContentType方法将会返回boundary + //httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);