|
@@ -1,7 +1,7 @@
|
|
|
package com.wj.service.impl;
|
|
package com.wj.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import org.json.JSONArray;
|
|
|
|
|
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
@@ -9,19 +9,21 @@ import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
public class SaveRecord {
|
|
public class SaveRecord {
|
|
|
|
|
|
|
|
- //private static final String sqlurl = PropertiesConfig.getSqlurl();
|
|
|
|
|
-
|
|
|
|
|
public static boolean saverecord(String sqlurl, String ucid, String url) {
|
|
public static boolean saverecord(String sqlurl, String ucid, String url) {
|
|
|
HttpURLConnection con = null;
|
|
HttpURLConnection con = null;
|
|
|
try {
|
|
try {
|
|
|
- // 创建JSON对象并填充数据
|
|
|
|
|
- JSONObject json = new JSONObject();
|
|
|
|
|
- json.put("ucid", ucid);
|
|
|
|
|
- json.put("url", url);
|
|
|
|
|
- // 创建一个空的JSONArray作为外层包裹
|
|
|
|
|
|
|
+ // 创建一个JSONObject对象
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
|
+ // 创建一个JSONArray对象,用于存放data数组
|
|
|
JSONArray dataArray = new JSONArray();
|
|
JSONArray dataArray = new JSONArray();
|
|
|
- // 将你的JSON对象添加到空的JSONArray中
|
|
|
|
|
- dataArray.put(json);
|
|
|
|
|
|
|
+ // 创建两个JSONObject对象,分别表示data数组中的两个元素
|
|
|
|
|
+ JSONObject item1 = new JSONObject();
|
|
|
|
|
+ item1.put("ucid", ucid);
|
|
|
|
|
+ item1.put("url", url);
|
|
|
|
|
+ // 将两个JSONObject对象添加到dataArray中
|
|
|
|
|
+ dataArray.add(item1);
|
|
|
|
|
+ // 将dataArray添加到jsonObject中
|
|
|
|
|
+ jsonObject.put("data", dataArray);
|
|
|
// 创建连接
|
|
// 创建连接
|
|
|
URL urlObj = new URL(sqlurl);
|
|
URL urlObj = new URL(sqlurl);
|
|
|
con = (HttpURLConnection) urlObj.openConnection();
|
|
con = (HttpURLConnection) urlObj.openConnection();
|
|
@@ -32,7 +34,7 @@ public class SaveRecord {
|
|
|
|
|
|
|
|
// 发送POST请求
|
|
// 发送POST请求
|
|
|
con.setDoOutput(true);
|
|
con.setDoOutput(true);
|
|
|
- byte[] out = dataArray.toString().getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
|
|
+ byte[] out = jsonObject.toString().getBytes(StandardCharsets.UTF_8);
|
|
|
con.setFixedLengthStreamingMode(out.length);
|
|
con.setFixedLengthStreamingMode(out.length);
|
|
|
con.getOutputStream().write(out);
|
|
con.getOutputStream().write(out);
|
|
|
System.out.println(con.getResponseCode());
|
|
System.out.println(con.getResponseCode());
|