| | |
| | | package com.example; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import org.junit.jupiter.api.Test;; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStreamWriter; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.util.Map; |
| | | |
| | | @SpringBootTest |
| | | class ImgCheckApplicationTests { |
| | |
| | | void contextLoads() { |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | URL url = null; |
| | | HttpURLConnection connection = null; |
| | | OutputStreamWriter writer = null; |
| | | BufferedReader reader = null; |
| | | StringBuilder response = new StringBuilder(); |
| | | try { |
| | | url = new URL("http://oapi.xamjyy.com/OAPI/zhuShuJu/getShouFeiXm"); |
| | | connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("POST"); |
| | | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| | | connection.setRequestProperty("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyI2MjY0MTYyNTk2MTY5OTczNzYiXSwiZXhwIjoxNzM0NzkyMzk2LCJqdGkiOiJhYjg0YWNjZi0xMDYyLTRjNDUtYjdhNy04OGVkYmQ4ZTdmYmMiLCJjbGllbnRfaWQiOiJYRlpaUUVmWFRaN2V4aGhpIn0.CothzTpZoz08Kvb8z3FIl0CtZQhc5p12H0oHmmdp1gQ"); |
| | | connection.setDoOutput(true); |
| | | StringBuilder postData = new StringBuilder(); |
| | | JSONObject jsonObject = JSONUtil.parseObj("{\"pageIndex\":1,\"pageSize\":10}"); |
| | | for (String key : jsonObject.keySet()) { |
| | | if (postData.length() > 0) { |
| | | postData.append("&"); |
| | | } |
| | | String encode = URLEncoder.encode(key, "UTF-8"); |
| | | String encode1 = URLEncoder.encode(String.valueOf(jsonObject.get(key)), "UTF-8"); |
| | | postData.append(encode).append("=").append(encode1); |
| | | } |
| | | writer = new OutputStreamWriter(connection.getOutputStream()); |
| | | System.out.println("postData = " + postData); |
| | | writer.write(postData.toString()); |
| | | writer.flush(); |
| | | reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | response.append(line); |
| | | } |
| | | System.out.println("response = " + response); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |