public class Main { public static void main(String[] args) throws Exception { String url = "https://yzzyet.11185.cn/app/api/GpyService/getConnectionCheck"; String method = "getConnectionCheck"; String V_MARK = ""; // Assign your V_MARK value String V_JGBH = ""; // Assign your V_JGBH value String KEY = ""; // Assign your KEY value String company = ""; // Assign your company value
String sData = "{" + "\"V_MARK\":\"" + V_MARK + "\",\"V_JGBH\":\"" + V_JGBH + "\",\"method\":\"" + method + "\"" + "}"; String bsData = Base64.getEncoder().encodeToString(sData.getBytes("UTF-8")); String dataMD5 = Utility.MD5Encrypt(bsData); Map<String, Object> postData = new HashMap<>(); postData.put("data", bsData); postData.put("sign", dataMD5 + KEY + company); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("POST"); connection.setConnectTimeout(2300); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setDoOutput(true); DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); outputStream.writeBytes(getParamsString(postData)); outputStream.flush(); outputStream.close(); int rtcode = connection.getResponseCode(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); System.out.println(response.toString()); } private static String getParamsString(Map<String, Object> params) throws Exception { StringBuilder result = new StringBuilder(); for (Map.Entry<String, Object> entry : params.entrySet()) { if (result.length() != 0) result.append("&"); result.append(entry.getKey()); result.append("="); result.append(entry.getValue()); } return result.toString(); } // You need to implement Utility.MD5Encrypt and Utility.Base64Encode methods here }