Frost před 1 rokem
rodič
revize
2354c002be

+ 7 - 0
pom.xml

@@ -41,6 +41,13 @@
             <version>2.3.5.RELEASE</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>20210307</version>
+        </dependency>
+
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-configuration-processor</artifactId>

+ 2 - 4
src/main/java/com/wj/Application.java

@@ -1,7 +1,5 @@
 package com.wj;
 
-import com.wj.exception.CustomXmlParseException;
-import com.wj.exception.SSLUtil;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -11,8 +9,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableScheduling
 public class Application {
 
-    public static void main(String[] args) throws CustomXmlParseException {
-        SSLUtil.ignoreSSLVerification();
+    public static void main(String[] args)  {
+
         SpringApplication.run(Application.class, args);
     }
 }

+ 0 - 33
src/main/java/com/wj/exception/SSLUtil.java

@@ -1,33 +0,0 @@
-package com.wj.exception;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import java.security.cert.X509Certificate;
-
-public class SSLUtil {
-    public static void ignoreSSLVerification() throws CustomXmlParseException {
-        try {
-            TrustManager[] trustAllCertificates = new TrustManager[]{
-                    new X509TrustManager() {
-                        public X509Certificate[] getAcceptedIssuers() {
-                            return null;
-                        }
-
-                        public void checkClientTrusted(X509Certificate[] certs, String authType) {
-                        }
-
-                        public void checkServerTrusted(X509Certificate[] certs, String authType) {
-                        }
-                    }
-            };
-
-            SSLContext sslContext = SSLContext.getInstance("TLS");
-            sslContext.init(null, trustAllCertificates, new java.security.SecureRandom());
-            HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
-        } catch (Exception e) {
-            throw new CustomXmlParseException(e);
-        }
-    }
-}

+ 6 - 2
src/main/java/com/wj/service/impl/SaveRecord.java

@@ -1,6 +1,7 @@
 package com.wj.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import org.json.JSONArray;
 
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -17,7 +18,10 @@ public class SaveRecord {
             JSONObject json = new JSONObject();
             json.put("ucid", ucid);
             json.put("url", url);
-
+            // 创建一个空的JSONArray作为外层包裹
+            JSONArray dataArray = new JSONArray();
+            // 将你的JSON对象添加到空的JSONArray中
+            dataArray.put(json);
             // 创建连接
             URL urlObj = new URL(sqlurl);
             con = (HttpURLConnection) urlObj.openConnection();
@@ -28,7 +32,7 @@ public class SaveRecord {
 
             // 发送POST请求
             con.setDoOutput(true);
-            byte[] out = json.toString().getBytes(StandardCharsets.UTF_8);
+            byte[] out = dataArray.toString().getBytes(StandardCharsets.UTF_8);
             con.setFixedLengthStreamingMode(out.length);
             con.getOutputStream().write(out);
             System.out.println(con.getResponseCode());