From 763ef6b8bca55522775a20edc3095610a94450aa Mon Sep 17 00:00:00 2001 From: xyiege Date: Thu, 22 Sep 2022 02:07:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=92=A4=E9=94=80=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=8F=90=E4=BA=A4=E6=96=B9=E5=BC=8F=E4=B8=BAget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/chjyj/szwh/utils/SzwhApiUtils.java | 28 +++++++++++++++---- urls.md | 4 ++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java index 4589754..6de5649 100644 --- a/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java +++ b/src/main/java/cn/chjyj/szwh/utils/SzwhApiUtils.java @@ -6,7 +6,10 @@ import com.alibaba.fastjson2.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.http.client.utils.URIBuilder; +import java.net.URISyntaxException; +import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -54,15 +57,28 @@ public class SzwhApiUtils { Map hmap = new HashMap(); hmap.put("entrust_token",sign); - //请求参数 转为json - JSONObject rparam = new JSONObject(); + //请求参数map + Map rparam = new HashMap(); rparam.put("revokeReason",reason); rparam.put("isliCode",goodsIslicode); - rparam.put("status",3); - String params=rparam.toString(); + rparam.put("status","3"); + //构建url请求地址 + try { + URIBuilder builder = new URIBuilder(url); + if (rparam != null) { + for (String key : rparam.keySet()) { + builder.addParameter(key, rparam.get(key)); + } + //请求的地址信息 + url= builder.toString(); + } + }catch (URISyntaxException ex){ + log.error("off goods urisyntax exception:"+ex.toString()); + ex.printStackTrace(); + } - // 发送post请求 - JSONObject json = RequestUtils.postData(url,params,hmap); + // 发送get方式,urlpararam格式 + JSONObject json = RequestUtils.GetData(url,hmap,false); return json; } diff --git a/urls.md b/urls.md index 9358aad..f05352b 100644 --- a/urls.md +++ b/urls.md @@ -34,4 +34,6 @@ 16.[字节流InputStream和OutputStream、向文件读写内容](https://blog.csdn.net/Tir_zhang/article/details/124733876) -17.[StringUtils工具类常用方法](https://www.cnblogs.com/jmcui/p/7208383.html) \ No newline at end of file +17.[StringUtils工具类常用方法](https://www.cnblogs.com/jmcui/p/7208383.html) + +18.[JAVA发送GET、POST请求,携带请求头,接收解析返回值(通过URL)](https://blog.csdn.net/HezhezhiyuLe/article/details/92395041) \ No newline at end of file