springboot3通过HttpRequest请求soap
http://10.20.0.11:80/wms/index.php/Home/SOAP/getVehStatus为请求地址
其中所有的getOfflineAmount字段都是调用的方法名
public static String getOfflineAmount() {
String result2 = HttpRequest.post("http://10.20.0.11:80/wms/index.php/Home/SOAP/getVehStatus")
.header(Header.USER_AGENT, "Hutool http")
.header("SOAPAction", "urn:Veh##getOfflineAmount")
.header("Content-Type", "ext/xml;charset=UTF-8")
.body(
"<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:urn=\"urn:Veh\">\n"
+ " <soapenv:Header/>\n"
+ " <soapenv:Body>\n"
+ " <urn:getOfflineAmount soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
//需要传的参数 vin和stationId是字段名 vin和stationCode是字段值
//+ " <vin xsi:type=\"xsd:string\">" + vin + "</vin>\n"
//+ " <stationId xsi:type=\"xsd:string\">" + stationCode + "</stationId>\n"
+ " </urn:getOfflineAmount>\n"
+ " </soapenv:Body>\n"
+ "</soapenv:Envelope>")
.timeout(20000)//超时,毫秒
.execute().body();
Document docResult = XmlUtil.readXML(result2);
Object value = XmlUtil.getByXPath("//SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:getOfflineAmountResponse/getOfflineAmount", docResult, XPathConstants.STRING);
if (!"error".equalsIgnoreCase(value.toString())) {
return value.toString();
} else {
return null;
}
}