我正在尝试使用node-soap访问 National Rail API 。
文档在这里:https ://lite.realtime.nationalrail.co.uk/OpenLDBWS/
我是 SOAP 新手,所以这可能不是 API 的问题。无论我尝试什么,我都会遇到 TypeError...
TypeError:无法读取未定义的属性“正文”
这是我用来尝试拨打电话的代码:
var soap = require('soap');
var url = 'https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2014-02-20';
var soapHeader = '<com:AccessToken>MY_TOKEN</com:AccessToken>';
soap.createClient(url, function(err, client){
var args = {
numRows : 10,
crs : 'LAN'
};
client.addSoapHeader(soapHeader);
client.GetDepartureBoard(args, function(err, result){
if(err){
console.log('error!');
throw err;
}
console.log(result);
});
});
使用 node-soap 我还可以获得请求信封,这是内容:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://thalesgroup.com/RTTI/2014-02-20/ldb/"
xmlns:tok="http://thalesgroup.com/RTTI/2013-11-28/Token/types"
xmlns:ct="http://thalesgroup.com/RTTI/2007-10-10/ldb/commontypes"
xmlns:ldbt="http://thalesgroup.com/RTTI/2012-01-13/ldb/types"
xmlns:ldbt2="http://thalesgroup.com/RTTI/2014-02-20/ldb/types">
<soap:Header>
<com:AccessToken>MY_TOKEN</com:AccessToken>
</soap:Header>
<soap:Body>
<tns:GetDepartureBoardRequest
xmlns:tns="http://thalesgroup.com/RTTI/2014-02-20/ldb/"
xmlns="http://thalesgroup.com/RTTI/2014-02-20/ldb/">
<tns:numRows>10</tns:numRows>
<tns:crs>LAN</tns:crs>
</tns:GetDepartureBoardRequest>
</soap:Body>
</soap:Envelope>