我正在尝试使用Estes Shipment Tracking Web Services构建一款货运跟踪工具,该服务使用SOAP协议。我与其Web支持团队交流后,他们能够使用SOAPUI创建一个使用我的凭据接收有效响应的工作请求。看起来,我的问题在于无法在node.js中复制请求/响应的过程。为什么我无法在node.js中复制SOAPUI的请求/响应呢?
以下是Estes Web支持团队使用的已经生效的SOAPUI原始请求:
最后,这是我在response.xml中收到的错误:
以下是Estes Web支持团队使用的已经生效的SOAPUI原始请求:
POST https://api.estes-express.com:443/ws/estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking/estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Port HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder_shipmentTracking"
Content-Length: 468
Host: api.estes-express.com:443
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic XXXXX
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="https://api.estes-express.com/ws/tools/shipment/tracking/v1.1/">
<soapenv:Header/>
<soapenv:Body>
<v1:shipmentTracking>
<search>
<requestID>testroger</requestID>
<!--Optional:-->
<pro>XXXXXX</pro>
</search>
<debug>N</debug>
</v1:shipmentTracking>
</soapenv:Body>
</soapenv:Envelope>
上面我省略了base 64编码的基本身份验证信息,但我保证我在我的请求中使用了完全相同的值。
以下是我的请求,使用node.js。 我应该指出,在我的请求中提供了代理信息,但我已经验证它在其他请求函数中有效。
function estes(obj) {
var auth = 'Basic XXXXXXX'
var url = 'https://api.estes-express.com:443/ws/estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking/estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Port'
const request = require('request')
const fs = require('fs');
const xml = fs.readFileSync('estessample.xml', 'utf-8');
request.post({
uri: url,
headers: {
'SOAPAction': 'estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder_shipmentTracking',
'Content-Type': 'text/xml;charset=UTF-8',
'Content-Length': xml.length,
'Host': 'api.estes-express.com:443',
'Authorization': auth
},
proxy: 'XXXXXX',
body: xml
}, function (error, response, body) {
console.log(body)
fs.writeFile("response.txt", body, (err) => {
if (err) console.log(err);
console.log("Successfully Written to File.");
});
})
}
这是我向他们的服务(estessample.xml)发送的XML,与Estes网络服务团队使用的相同,并且已经被证明有效:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="https://api.estes-express.com/ws/tools/shipment/tracking/v1.1/">
<soapenv:Header/>
<soapenv:Body>
<v1:shipmentTracking>
<search>
<requestID>testroger</requestID>
<!--Optional:-->
<pro>XXXXXXX</pro>
</search>
<debug>N</debug>
</v1:shipmentTracking>
</soapenv:Body>
</soapenv:Envelope>
最后,这是我在response.xml中收到的错误:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>[ISS.0088.9164] Access to WSDescriptor estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking denied.</faultstring>
<faultactor>http://api.estes-express.com/tools</faultactor>
<detail>
<webM:exception xmlns:webM="http://www.webMethods.com/2001/10/soap/encoding">
<webM:className>com.wm.app.b2b.server.AccessException</webM:className>
<webM:message xml:lang="">[ISS.0088.9164] Access to WSDescriptor estesrtshipmenttracking.base.ws.provider.soapws:EstesShipmentTracking denied.</webM:message>
</webM:exception>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>