在Java中发送该报文,可以使用以下代码:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class SendJSON {

    public static void main(String[] args) {

        try {
            // 设置请求URL
            URL url = new URL("http://example.com");
            // 创建HttpURLConnection对象
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            // 设置请求方式
            conn.setRequestMethod("POST");
            // 设置请求头
            conn.setRequestProperty("Content-Type", "application/json");
            // 设置请求体
            conn.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
            out.write("{\"EsbHeader\":{\"SrcSysId\":\"0504\",\"SrcCalCod\":\"DEM\",\"GloSeqNo\":\"12134565789101\"},\"Header\":{\"Action\":\"http://www.dongguanbank.cn/G0120006/03\",\"Address\":\"0504\"},\"APPHeader\":null,\"APPBody\":{\"msg_list\":[{\"key_list\":[],\"phone\":\"13800138000\",\"userno\":\"641752804639\",\"vercodeefftime\":\"120\",\"isdigitret\":\"Y\"}],\"templateno\":\"FNC_000042\"}}");
            out.flush();
            out.close();
            // 获取响应结果
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = in.readLine()) != null) {
                response.append(line);
            }
            in.close();
            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

其中,需要替换以下内容:

  • 请求URL:将"http://example.com"替换为实际的请求URL。
  • 请求体:将JSON字符串替换为实际的请求体。
curl -X POST -H Content-Typeapplicationjson --data EsbHeaderSrcSysId0504SrcCalCodDEMGloSeqNo12134565789101HeaderActionhttpwwwdongguanbankcnG012000603Address0504APPHeadernullAPPBodymsg_listkey_listphon

原文地址: https://www.cveoy.top/t/topic/b2if 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录