From 66a1d779057d1c9fc75abd30218546a419b7b442 Mon Sep 17 00:00:00 2001 From: zjh <zjh@888> Date: 星期三, 05 六月 2024 14:31:44 +0800 Subject: [PATCH] zjh 本地 2024/06/05 --1 --- ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java | 21 +++++++++------------ 1 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java b/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java index 6412b31..f46fdcd 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/wxUtils/HttpClientUtils.java @@ -1,6 +1,8 @@ package com.ltkj.web.wxUtils; +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; @@ -35,6 +37,7 @@ * @create 2019-02-10 涓嬪崍 2:49 */ @Component +@Slf4j public class HttpClientUtils { /** @@ -99,27 +102,19 @@ URL url = new URL(httpUrl); // 2. 鍒涘缓 HttpURLConnection 瀵硅薄 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - // 3. 璁剧疆璇锋眰鏂规硶涓� POST connection.setRequestMethod("POST"); - // 4. 璁剧疆 Content-Type 澶撮儴瀛楁 connection.setRequestProperty("Content-Type", "application/json"); - - // 5. 璁剧疆鍏朵粬璇锋眰澶撮儴瀛楁锛堝彲閫夛級 -// connection.setRequestProperty("Authorization", "Bearer token"); -// connection.setRequestProperty("User-Agent", "Mozilla/5.0"); - // 6. 鍚戞湇鍔″櫒鍙戦�佹暟鎹� - String requestBody = maps.toString(); + String requestBody = JSONUtil.toJsonStr(maps); + log.info(httpUrl+"鍏ュ弬: "+requestBody); +// String requestBody1 = maps.toString(); byte[] postData = requestBody.getBytes("UTF-8"); connection.setDoOutput(true); try (OutputStream outputStream = connection.getOutputStream()) { outputStream.write(postData); } - - // 7. 鑾峰彇鍝嶅簲鐮� - int responseCode = connection.getResponseCode(); // 8. 鑾峰彇鍝嶅簲鏁版嵁 try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { @@ -128,7 +123,9 @@ while ((line = reader.readLine()) != null) { response.append(line); } - System.out.println(response.toString()); + log.info("====================================================="); + log.info(httpUrl+"鍑哄弬"); + log.info(response.toString()); connection.disconnect(); return response.toString(); } -- Gitblit v1.8.0