node.js - SOAPUI 和 Node.JS/Request-AccessException
问题描述
我正在尝试使用使用 SOAP 的 Estes Shipment Tracking Web Services 构建一个货运跟踪工具。我与他们的网络支持人员进行了交谈,他们能够使用 SOAPUI 创建一个工作请求,该请求使用我的凭据接收有效响应。看来我的问题是无法使用 node.js 在 SOAPUI 中复制请求/响应。为什么我无法在 node.js 中复制 SOAPUI 请求/响应?
以下是 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 Web 服务团队在上面使用的相同:
<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>
解决方案
该错误是由于身份验证错误造成的。我刚刚尝试访问端点并收到类似的错误。
我相信你正在使用这个节点模块https://github.com/request/request
在浏览了您共享的代码后,我认为这可能是由于您形成 POST 请求的方式。我建议request
更彻底地阅读模块文档。
request.post({
uri: url,
headers: {
'SOAPAction': 'estesrtshipmenttracking_base_ws_provider_soapws_EstesShipmentTracking_Binder_shipmentTracking',
'Content-Type': 'text/xml;charset=UTF-8'
},
'auth': {
'user': '<username>',
'pass': '<password>',
},
body: xml,
}, function (error, response, body) {
// Code Omitted
})
上面显示的简化示例。记下 auth 部分。该模块还将负责设置content-length
标题。
推荐阅读
- java - 如何在eclipse中为JavaFX项目修复“java.lang.IllegalStateException:未设置位置”
- javascript - 在 Laravel 中使用 Ajax 将数据插入 MySQL
- kubernetes - 无法在工作节点上获取 kubectl 日志
- lua - pandoc lua过滤器替换tex宏
- javascript - 如何使用 Nginx 服务器配置 Web 套接字?
- ruby-on-rails - Rails在查询中“不能引用数组”
- ios - FirebaseAuth UI Google SignIn 在 iOS 上启用 cookie
- node.js - 如何更新自制软件以准备在 macOS Mojave 上安装 node/npm
- c# - 如何解决此错误?从未分配的字段,并且始终具有空值
- javascript - 返回 Nan 而我的所有值都是数字类型