From 345e1a4cc6b8c14f16d2e61344acaadd9cb7d0a8 Mon Sep 17 00:00:00 2001 From: zhaoyinchuan Date: Wed, 29 Dec 2021 21:41:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dget=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87map=E4=BC=A0=E5=8F=82=E5=A4=B1=E8=B4=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../httpclientutil/HttpClientUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java b/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java index 79c5ed3..fe24edb 100644 --- a/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java +++ b/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java @@ -2,6 +2,8 @@ import java.io.IOException; import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -22,6 +24,7 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpTrace; +import org.apache.http.client.utils.URIBuilder; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; @@ -445,6 +448,21 @@ private static HttpResponse execute(HttpConfig config) throws HttpProcessExcepti Utils.info("请求地址:"+config.url().substring(0, (idx>0 ? idx : config.url().length()))); if(idx>0){ Utils.info("请求参数:"+config.url().substring(idx+1)); + } else { + Map param = config.map(); + if(param != null && !param.isEmpty()) { + try { + URIBuilder builder = new URIBuilder(config.url()); + if (param != null) { + for (String key : param.keySet()) { + builder.addParameter(key, (String) param.get(key)); + } + } + request.setURI(builder.build()); + } catch (URISyntaxException ex) { + ex.printStackTrace(); + } + } } } //执行请求操作,并拿到结果(同步阻塞) From ee2d4c901c2b6e1fe0ce4dee93d6927c49728a48 Mon Sep 17 00:00:00 2001 From: zhaoyinchuan Date: Wed, 29 Dec 2021 22:29:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dget=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87map=E4=BC=A0=E5=8F=82=E5=A4=B1=E8=B4=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/arronlong/httpclientutil/HttpClientUtil.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java b/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java index fe24edb..3fdf973 100644 --- a/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java +++ b/src/main/java/com/arronlong/httpclientutil/HttpClientUtil.java @@ -453,10 +453,8 @@ private static HttpResponse execute(HttpConfig config) throws HttpProcessExcepti if(param != null && !param.isEmpty()) { try { URIBuilder builder = new URIBuilder(config.url()); - if (param != null) { - for (String key : param.keySet()) { - builder.addParameter(key, (String) param.get(key)); - } + for (String key : param.keySet()) { + builder.addParameter(key, (String) param.get(key)); } request.setURI(builder.build()); } catch (URISyntaxException ex) {