How to send raw SOAP request in Java?

后端 未结 3 385
抹茶落季
抹茶落季 2021-01-03 03:00

I need to send a raw SOAP request to server. My request looks like

POST http://10.76.243.43:8080/registry/services/xds-iti18 HTTP/1.1
Accept-Encoding: gzip,         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 03:15

    Can you try like this: you need to replace the xmldata with yours:

       try {
            String xmldata = " your reuest";
            String hostname = "10.76.243.43";
            int port = 8080;
            InetAddress addr = InetAddress.getByName(hostname);
            Socket sock = new Socket(addr, port);
    
            //Send header
            String path = "registry/services/xds-iti18";
            BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
            wr.write("POST "+path + " HTTP/1.1\r\n");
            wr.write("Host: "+hostname+":"+port+"\r\n");
            wr.write("Content-Length: "+ xmldata.length() + "\r\n");
            wr.write("Content-Type: application/soap+xml; charset=\"utf-8\"\r\n");
            wr.write("\r\n");            //Send data
            wr.write(xmldata);
            wr.flush();
    
            // Response
            BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
              System.out.println("Response:"+line);
            }
    } catch (Exception e) {
       e.printStackTrace();
    }
    

提交回复
热议问题