This commit is contained in:
Looly 2022-04-01 12:10:09 +08:00
parent 2fce7eab06
commit 0986e60a7c
5 changed files with 38 additions and 3 deletions

View File

@ -7,6 +7,7 @@
### ❌不兼容特性
* 【extra 】 【可能兼容问题】BeanCopierCache的key结构变更
* 【http 】 【可能兼容问题】HttpInterceptor增加泛型标识HttpRequest中配置汇总于HttpConfig
* 【core 】 【可能兼容问题】UrlQuery.addQuery参数2从String变更为Object
### 🐣新特性
* 【core 】 MapUtil增加entry、ofEntries方法
@ -21,6 +22,7 @@
* 【core 】 IdcardUtil#getCityCodeByIdCard位数问题issue#2224@Github
* 【core 】 修复urlWithParamIfGet函数逻辑问题issue#I50IUD@Gitee
* 【core 】 修复IoUtil.readBytes限制长度读取问题issue#2230@Github
* 【http 】 修复HttpRequest中编码对URL无效的问题issue#I50NHQ@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -399,7 +399,7 @@ public final class UrlBuilder implements Builder<String> {
* @param value
* @return this
*/
public UrlBuilder addQuery(String key, String value) {
public UrlBuilder addQuery(String key, Object value) {
if (StrUtil.isEmpty(key)) {
return this;
}

View File

@ -9,6 +9,8 @@ import org.junit.Test;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
public class UrlBuilderTest {
@ -389,4 +391,18 @@ public class UrlBuilderTest {
final String build = UrlBuilder.of(url, null).build();
Assert.assertEquals(url, build);
}
@Test
public void issueI50NHQTest(){
String url = "http://127.0.0.1/devicerecord/list";
HashMap<String, Object> params = new LinkedHashMap<>();
params.put("start", "2022-03-31 00:00:00");
params.put("end", "2022-03-31 23:59:59");
params.put("page", 1);
params.put("limit", 10);
final UrlBuilder builder = UrlBuilder.of(url);
params.forEach(builder::addQuery);
Assert.assertEquals("http://127.0.0.1/devicerecord/list?start=2022-03-31%2000:00:00&end=2022-03-31%2023:59:59&page=1&limit=10", builder.toString());
}
}

View File

@ -1077,7 +1077,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
@Override
public String toString() {
StringBuilder sb = StrUtil.builder();
sb.append("Request Url: ").append(this.url).append(StrUtil.CRLF);
sb.append("Request Url: ").append(this.url.setCharset(this.charset)).append(StrUtil.CRLF);
sb.append(super.toString());
return sb.toString();
}
@ -1135,7 +1135,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
}
this.httpConnection = HttpConnection
.create(this.url.toURL(this.urlHandler), config.proxy)//
// issue#I50NHQ
// 在生成正式URL前设置自定义编码
.create(this.url.setCharset(this.charset).toURL(this.urlHandler), config.proxy)//
.setConnectTimeout(config.connectionTimeout)//
.setReadTimeout(config.readTimeout)//
.setMethod(this.method)//

View File

@ -193,4 +193,19 @@ public class HttpRequestTest {
HttpRequest request =HttpUtil.createGet(url).form(map);
Console.log(request.execute().body());
}
@Test
public void issueI50NHQTest(){
String url = "http://127.0.0.1/devicerecord/list";
HashMap<String, Object> params = new HashMap<>();
params.put("start", "2022-03-31 00:00:00");
params.put("end", "2022-03-31 23:59:59");
params.put("page", 1);
params.put("limit", 10);
String result = HttpRequest.get(url)
.header("token", "123")
.form(params).toString();
Console.log(result);
}
}