我想使用 JAVA 检索 XML 响应(SOAP 网络服务)。 客户端将以 XML 格式发送请求,java 代码应该能够接收 XML 格式的响应。
一个XML的例子如下:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="WebService">
<soapenv:Header/>
<soapenv:Body>
<web:SystemStatus soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<order xsi:type="xsd:int">?</order>
</web:SystemStatus>
</soapenv:Body>
</soapenv:Envelope>
您能否建议使用 java 实现的步骤?
最佳答案
如果你知道请求,你可以使用java.net.HttpURLConnection
String soapXml = "";// your request_xml_in_question
java.net.URL url = new java.net.URL("your_Service_url");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Set the necessary header fields
conn.setRequestProperty("SOAPAction", "your_Service_url");
conn.setDoOutput(true);
// Send the request
java.io.OutputStreamWriter wr = new java.io.OutputStreamWriter(conn.getOutputStream());
wr.write(soapXml);
wr.flush();
// Read the response
java.io.BufferedReader rd = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
关于java - 如何从 soap web 服务检索未知的 XML 并使用 java 插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60835116/