Skip to content

Commit 0886fa0

Browse files
RayL555Binary Wang
authored andcommitted
🎨【公共】修复下载文件相关接口获取文件名的问题
1 parent 9816fdf commit 0886fa0

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package me.chanjar.weixin.common.util.http;
22

33
import jodd.http.HttpResponse;
4-
import me.chanjar.weixin.common.error.WxError;
54
import me.chanjar.weixin.common.error.WxErrorException;
65
import okhttp3.Response;
76
import org.apache.http.Header;
87
import org.apache.http.client.methods.CloseableHttpResponse;
98

10-
import java.util.regex.Matcher;
11-
import java.util.regex.Pattern;
12-
139
/**
1410
* <pre>
1511
* 三种http框架的response代理类,方便提取公共方法
@@ -19,7 +15,6 @@
1915
* @author <a href="https://github.com/binarywang">Binary Wang</a>
2016
*/
2117
public class HttpResponseProxy {
22-
private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\"");
2318

2419
private CloseableHttpResponse apacheHttpResponse;
2520
private HttpResponse joddHttpResponse;
@@ -79,9 +74,11 @@ private String extractFileNameFromContentString(String content) throws WxErrorEx
7974
throw new WxErrorException("无法获取到文件名,content为空");
8075
}
8176

82-
Matcher m = PATTERN.matcher(content);
83-
if (m.matches()) {
84-
return m.group(1);
77+
int startIndex = content.indexOf("filename=\"");
78+
if (startIndex != -1) {
79+
startIndex += "filename=\"".length();
80+
int endIndex = content.indexOf('"', startIndex);
81+
return content.substring(startIndex, endIndex);
8582
}
8683

8784
throw new WxErrorException("无法获取到文件名,header信息有问题");

0 commit comments

Comments
 (0)