From 911f75e6bdf21df717026b26e6864e0dd1a77bc7 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 14 Mar 2022 22:49:32 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 3 ++- hutool-http/src/main/java/cn/hutool/http/HttpRequest.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4ee93a7..03a556481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.7.23 (2022-03-13) +# 5.7.23 (2022-03-14) ### 🐣新特性 * 【http 】 HttpRequest.form采用TableMap方式(issue#I4W427@Gitee) @@ -19,6 +19,7 @@ * 【core 】 修复NumberConverter对数字转换的问题(issue#I4WPF4@Gitee) * 【core 】 修复ReflectUtil.getMethods获取接口方法问题(issue#I4WUWR@Gitee) * 【core 】 修复NamingCase中大写转换问题(pr#572@Gitee) +* 【http 】 修复GET重定向时,携带参数问题(issue#2189@Github) ------------------------------------------------------------------------------------------------------------- # 5.7.22 (2022-03-01) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java index 927c8bd4d..73883f0c7 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -1161,10 +1161,11 @@ public class HttpRequest extends HttpBase { /** * 对于GET请求将参数加到URL中
- * 此处不对URL中的特殊字符做单独编码 + * 此处不对URL中的特殊字符做单独编码
+ * 对于非rest的GET请求,且处于重定向时,参数丢弃 */ private void urlWithParamIfGet() { - if (Method.GET.equals(method) && false == this.isRest) { + if (Method.GET.equals(method) && false == this.isRest && this.redirectCount > 0) { // 优先使用body形式的参数,不存在使用form if (ArrayUtil.isNotEmpty(this.bodyBytes)) { this.url.getQuery().parse(StrUtil.str(this.bodyBytes, this.charset), this.charset); @@ -1194,7 +1195,7 @@ public class HttpRequest extends HttpBase { if (responseCode != HttpURLConnection.HTTP_OK) { if (HttpStatus.isRedirected(responseCode)) { - setUrl(httpConnection.header(Header.LOCATION)); + setUrl(UrlBuilder.ofHttpWithoutEncode(httpConnection.header(Header.LOCATION))); if (redirectCount < this.maxRedirectCount) { redirectCount++; // 重定向不再走过滤器