mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix urlQuery NullPointerException
This commit is contained in:
parent
2b79119c00
commit
a49ed29552
@ -12,6 +12,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.map.TableMap;
|
||||
import cn.hutool.core.net.SSLUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -1173,6 +1174,10 @@ 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());
|
||||
}
|
||||
|
||||
// 优先使用body形式的参数,不存在使用form
|
||||
if (ArrayUtil.isNotEmpty(this.bodyBytes)) {
|
||||
this.url.getQuery().parse(StrUtil.str(this.bodyBytes, this.charset), this.charset);
|
||||
|
@ -2,8 +2,10 @@ 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;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@ -193,4 +195,15 @@ public class HttpRequestTest {
|
||||
HttpRequest request =HttpUtil.createGet(url).form(map);
|
||||
Console.log(request.execute().body());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void urlWithParamIfGet(){
|
||||
UrlBuilder urlBuilder = new UrlBuilder();
|
||||
urlBuilder.setScheme("https").setHost("hutool.cn");
|
||||
|
||||
HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
||||
httpRequest.setMethod(Method.GET);
|
||||
HttpResponse httpResponse = httpRequest.execute();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user