SOAPUI和Node.JS/Request - 访问异常

6
我正在尝试使用Estes Shipment Tracking Web Services构建一款货运跟踪工具,该服务使用SOAP协议。我与其Web支持团队交流后,他们能够使用SOAPUI创建一个使用我的凭据接收有效响应的工作请求。看起来,我的问题在于无法在node.js中复制请求/响应的过程。为什么我无法在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网络服务团队使用的相同,并且已经被证明有效:

<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>

现有答案有更新吗?是否有帮助? - Tarun Lalwani
@TarunLalwani 很遗憾,它没有起作用。 - Shane Sepac
看起来你在这里使用了代理,我怀疑它可能是导致问题的原因之一。我建议你先在没有代理的环境中进行测试。 - Tarun Lalwani
@TarunLalwani 尽管我在同一台机器上向其他 API 发出请求时代理有效,但当我停止使用代理时它就无法工作。我确信代理已经正确设置,但可能会干扰请求吗? - Shane Sepac
你的意思是 SOAP API 还是普通 API?此外,同一服务器上的其他 API 是否已经进行了测试?你能否仍然在直接连接互联网的情况下测试,以确保百分之百的问题排除。我们必须采用排除法的理论。 - Tarun Lalwani
2个回答

1
由于认证错误导致的错误。我刚刚尝试访问端点并收到了类似的错误。
我相信您正在使用这个节点模块 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头信息的工作。

这对我没有解决问题。我正在使用您发送的具有有效身份验证凭据的确切代码... - Shane Sepac
1
我不确定为什么它不起作用。SoapUI有一个免费版本,你可以尝试使用它来发出相同的请求。问题显示你正在使用一些代理,如果仍然是这种情况,请尝试在没有代理的情况下进行测试。 - Josnidhin

0
在尝试在多个网络上使Estes的SOAP服务正常工作的许多小时后,我无法成功。但是,我找到了一个可行的解决方法。
创建一个HTTP请求并POST到以下内容:https://myestes-api.estes-express.com/shipmenttracking/search 然后,在您的请求正文中发送以下模式,并确保替换为您的PRO编号。
{
    "session": "",
    "type": "PRO",
    "search": "<MY_PRO_NUMBER>",
    "sort": "",
    "direction": "",
    "rowsPerPage": "25",
    "page": "1",
    "totalPages": "1"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接