fix null bug

This commit is contained in:
Looly
2022-04-10 11:18:54 +08:00
parent fbeb5ab28b
commit 569877e0ef
5 changed files with 20 additions and 11 deletions

View File

@@ -1174,15 +1174,17 @@ public class HttpRequest extends HttpBase<HttpRequest> {
*/
private void urlWithParamIfGet() {
if (Method.GET.equals(method) && false == this.isRest && this.redirectCount <= 0) {
if (this.url.getQuery() == null) {
this.url.setQuery(new UrlQuery());
UrlQuery query = this.url.getQuery();
if (null == query) {
query = new UrlQuery();
this.url.setQuery(query);
}
// 优先使用body形式的参数不存在使用form
if (ArrayUtil.isNotEmpty(this.bodyBytes)) {
this.url.getQuery().parse(StrUtil.str(this.bodyBytes, this.charset), this.charset);
query.parse(StrUtil.str(this.bodyBytes, this.charset), this.charset);
} else {
this.url.getQuery().addAll(this.form);
query.addAll(this.form);
}
}
}

View File

@@ -2,7 +2,6 @@ package cn.hutool.http;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Console;
import cn.hutool.core.net.SSLProtocols;
import cn.hutool.core.net.url.UrlBuilder;
@@ -198,12 +197,11 @@ public class HttpRequestTest {
@Test
@Ignore
public void urlWithParamIfGet(){
public void urlWithParamIfGetTest(){
UrlBuilder urlBuilder = new UrlBuilder();
urlBuilder.setScheme("https").setHost("hutool.cn");
HttpRequest httpRequest = new HttpRequest(urlBuilder);
httpRequest.setMethod(Method.GET);
HttpResponse httpResponse = httpRequest.execute();
httpRequest.setMethod(Method.GET).execute();
}
}