16 changed files with 336 additions and 109 deletions
@ -0,0 +1,91 @@ |
|||||||
|
package com.biutag.supervision.tools; |
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest; |
||||||
|
import org.json.JSONArray; |
||||||
|
import org.json.JSONException; |
||||||
|
import org.json.JSONObject; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Auther: sh |
||||||
|
* @Date: 2025/1/7 23:09 |
||||||
|
* @Description: |
||||||
|
*/ |
||||||
|
//@SpringBootTest
|
||||||
|
public class HttpTest { |
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// String result2 = "{\n" +
|
||||||
|
// " \"data\": [\n" +
|
||||||
|
// "\t{\n" +
|
||||||
|
// " \"id\": \"FE0F0C0D6B6E48D5AAC06767822E9E53\",\n" +
|
||||||
|
// " \"upGovId\": \"0658014A81F140D2AC765806833A76C9\",\n" +
|
||||||
|
// " \"areaCode\": \"430197\",\n" +
|
||||||
|
// " \"code\": \"430197470000\",\n" +
|
||||||
|
// " \"name\": \"部门1\"\n" +
|
||||||
|
// " }\n" +
|
||||||
|
// "\t],\n" +
|
||||||
|
// " \"resCode\": 0,\n" +
|
||||||
|
// " \"resMsg\": \"\"\n" +
|
||||||
|
// "}\n";
|
||||||
|
@Test |
||||||
|
public void HttpTest() throws JSONException { |
||||||
|
String url = "http://11.33.3.4/api/v5/exporttable?id=BABA806481B64DF3BB0D04BE14A6DBD5"; |
||||||
|
String cookie = "tokenId=f91363e6f267361d2249eafeb2b517f8; JSESSIONID=322f2409-6f92-47ef-9cee-f8388b2c1f4c; SERVERID=5c39a0ebea6918a7ed3d1cd439f2f1e8|1737013998|1737013654"; |
||||||
|
try { |
||||||
|
// 获取初始数据
|
||||||
|
String result1 = HttpRequest.get(url).cookie(cookie).execute().body(); |
||||||
|
JSONObject jsonResponse = new JSONObject(result1); |
||||||
|
if (jsonResponse.getInt("resCode") == 0) { |
||||||
|
JSONArray dataArray = jsonResponse.getJSONArray("data"); |
||||||
|
|
||||||
|
// 遍历并处理每条数据
|
||||||
|
for (int i = 0; i < dataArray.length(); i++) { |
||||||
|
JSONObject data = dataArray.getJSONObject(i); |
||||||
|
String id = data.getString("id"); |
||||||
|
String upGovId = data.getString("upGovId"); |
||||||
|
String areaCode = data.getString("areaCode"); |
||||||
|
String code = data.getString("code"); |
||||||
|
String name = data.getString("name"); |
||||||
|
|
||||||
|
// 打印当前数据
|
||||||
|
printData(id, upGovId, areaCode, code, name); |
||||||
|
|
||||||
|
// 请求并处理内层数据
|
||||||
|
String innerUrl = "http://11.33.3.4/api/v5/exporttable?id=" + id; |
||||||
|
String result2 = HttpRequest.get(innerUrl).cookie(cookie).execute().body(); |
||||||
|
JSONObject jsonResponse2 = new JSONObject(result2); |
||||||
|
if (jsonResponse2.getInt("resCode") == 0) { |
||||||
|
JSONArray innerArray = jsonResponse2.getJSONArray("data"); |
||||||
|
|
||||||
|
// 遍历并打印内层数据
|
||||||
|
for (int j = 0; j < innerArray.length(); j++) { |
||||||
|
JSONObject innerData = innerArray.getJSONObject(j); |
||||||
|
String innerId = innerData.getString("id"); |
||||||
|
String innerUpGovId = innerData.getString("upGovId"); |
||||||
|
String innerAreaCode = innerData.getString("areaCode"); |
||||||
|
String innerCode = innerData.getString("code"); |
||||||
|
String innerName = innerData.getString("name"); |
||||||
|
|
||||||
|
// 打印内层数据
|
||||||
|
printData(innerId, innerUpGovId, innerAreaCode, innerCode, innerName); |
||||||
|
System.out.println("<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void printData(String id, String upGovId, String areaCode, String code, String name) { |
||||||
|
System.out.println("ID: " + id); |
||||||
|
System.out.println("UpGovId: " + upGovId); |
||||||
|
System.out.println("AreaCode: " + areaCode); |
||||||
|
System.out.println("Code: " + code); |
||||||
|
System.out.println("Name: " + name); |
||||||
|
System.out.println("------------------------------"); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue