From 5408346178dd12b7ab78fb51c76f59c300a7e153 Mon Sep 17 00:00:00 2001
From: ws <ws@123.com>
Date: 星期四, 31 十月 2024 23:37:31 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
src/main/java/com/fzzy/push/sx2024/SX2024HttpClientUtil.java | 80 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/fzzy/push/sx2024/SX2024HttpClientUtil.java b/src/main/java/com/fzzy/push/sx2024/SX2024HttpClientUtil.java
new file mode 100644
index 0000000..e179ffa
--- /dev/null
+++ b/src/main/java/com/fzzy/push/sx2024/SX2024HttpClientUtil.java
@@ -0,0 +1,80 @@
+package com.fzzy.push.sx2024;
+
+import com.fzzy.push.sx2023.data.SX2023RespDto;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * @Description 闄曡タ鐪佸钩鍙�2023鐗�-鏁版嵁涓婁紶鏈嶅姟
+ * @Author CZT
+ * @Date 2024/4/23 15:11
+ */
+@Slf4j
+public class SX2024HttpClientUtil {
+
+ public static String postPushData(String url, String reqData) throws Exception {
+ log.debug("---------鎺ュ彛璇锋眰鍦板潃锛�" + url + "----------鍙傛暟锛�" + reqData + "---------");
+ BufferedReader in = null;
+ URL urls = new URL(url);
+ HttpURLConnection connection = null;
+ OutputStream outputStream = null;
+ String rs = "";
+ SX2023RespDto responseDto;
+ try {
+
+ connection = (HttpURLConnection) urls.openConnection();
+ connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");
+ connection.setRequestProperty("Accept", "*/*");
+ connection.setRequestProperty("Range", "bytes=" + "");
+ connection.setConnectTimeout(20000);
+ connection.setReadTimeout(30000);
+ connection.setRequestMethod("POST");
+
+ outputStream = connection.getOutputStream();
+
+ outputStream.write(reqData.getBytes("UTF-8"));
+ try {
+ connection.connect();
+ if (connection.getResponseCode() == 200) {
+ in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
+ String line = "";
+ while ((line = in.readLine()) != null) {
+ rs += line;
+ }
+ } else {
+ log.error("http鐘舵�侊細" + connection.getResponseCode());
+ log.error("http娑堟伅锛�" + connection.getResponseMessage());
+ }
+
+ } catch (Exception e) {
+ System.out.println("鍙戠敓寮傚父");
+ log.error(e.getMessage(), e);
+ rs = null;
+ return rs;
+ }
+ log.info("---------鎺ュ彛杩斿洖锛�" + rs + "---------");
+ return rs;
+ } finally {
+ try {
+ outputStream.close();
+ if (in != null) {
+ in.close();
+ }
+ } catch (Exception e) {
+ }
+ outputStream = null;
+ if (connection != null)
+ connection.disconnect();
+ connection = null;
+ }
+ }
+
+}
--
Gitblit v1.9.3