From 4bbe6a2df8628226524618046118b72f09e5ec8c Mon Sep 17 00:00:00 2001 From: "weilin.zhu" Date: Thu, 5 Jan 2023 12:14:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=B7=E6=B1=82form?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=8F=90=E4=BA=A4=E6=97=B6=EF=BC=8C=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E8=A2=AB=E5=8F=8C=E5=BC=95=E5=8F=B7=E6=8B=AC?= =?UTF-8?q?=E4=BA=86=E8=B5=B7=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiyh/utils/httpUtil/util/HttpUtils.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java index bf4d92b..6967ec7 100644 --- a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java +++ b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java @@ -1003,14 +1003,20 @@ public class HttpUtils { if (Strings.isNullOrEmpty(contentType)) { List nvps = new ArrayList<>(); for (Map.Entry entry : params.entrySet()) { - nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + //nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + + //修复请求form表单提交时,参数值被双引号括了起来 + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); } httpPost.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); } else if (contentType.toUpperCase().startsWith(HttpArgsType.X_WWW_FORM_URLENCODED.toUpperCase())) { List nvps = new ArrayList<>(); for (Map.Entry entry : params.entrySet()) { - nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + //nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + + //修复请求form表单提交时,参数值被双引号括了起来 + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); } httpPost.setEntity(new UrlEncodedFormEntity(nvps)); // } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) { @@ -1187,14 +1193,18 @@ public class HttpUtils { if (Strings.isNullOrEmpty(contentType)) { List nvps = new ArrayList<>(); for (Map.Entry entry : paramsMap.entrySet()) { - nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + //nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + //修复请求form表单提交时,参数值被双引号括了起来 + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); } httpPut.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE); httpPut.setEntity(new UrlEncodedFormEntity(nvps)); } else if (contentType.toUpperCase().startsWith(HttpArgsType.X_WWW_FORM_URLENCODED.toUpperCase())) { List nvps = new ArrayList<>(); for (Map.Entry entry : paramsMap.entrySet()) { - nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + //nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + //修复请求form表单提交时,参数值被双引号括了起来 + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); } httpPut.setEntity(new UrlEncodedFormEntity(nvps)); } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) {