From 0886fa0fbd7d75ec3ac60bfd875442daec757d3e Mon Sep 17 00:00:00 2001 From: rayL <1061959822@qq.com> Date: Mon, 15 Jul 2024 13:28:02 +0000 Subject: [PATCH] =?UTF-8?q?:art:=E3=80=90=E5=85=AC=E5=85=B1=E3=80=91?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/common/util/http/HttpResponseProxy.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java index f338ece67..3e0acb46f 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java @@ -1,15 +1,11 @@ package me.chanjar.weixin.common.util.http; import jodd.http.HttpResponse; -import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; import okhttp3.Response; import org.apache.http.Header; import org.apache.http.client.methods.CloseableHttpResponse; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** *
* 三种http框架的response代理类,方便提取公共方法 @@ -19,7 +15,6 @@ import java.util.regex.Pattern; * @author Binary Wang */ public class HttpResponseProxy { - private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\""); private CloseableHttpResponse apacheHttpResponse; private HttpResponse joddHttpResponse; @@ -79,9 +74,11 @@ public class HttpResponseProxy { throw new WxErrorException("无法获取到文件名,content为空"); } - Matcher m = PATTERN.matcher(content); - if (m.matches()) { - return m.group(1); + int startIndex = content.indexOf("filename=\""); + if (startIndex != -1) { + startIndex += "filename=\"".length(); + int endIndex = content.indexOf('"', startIndex); + return content.substring(startIndex, endIndex); } throw new WxErrorException("无法获取到文件名,header信息有问题");