我正在尝试从酒店 channel 管理器的 API 获取 Ping 消息。 (XML开放旅游联盟)
我首先使用 SoapUI-5.3.0 工具发出 HTTP XML POST 请求,其中包含以下参数:
otaRQ: <OTA_PingRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="3.30" TimeStamp="2011-07-24T10:07:24" Target="Production"> <EchoData><![CDATA[Hello World!!]]> </EchoData> </OTA_PingRQ>
并收到以下 XML 响应:
<OTA_PingRS PrimaryLangID="en" Target="Production" TimeStamp="2017-03-21T09:43:55" Version="3.00" xmlns="http://www.opentravel.org/OTA/2003/05">
<Success/>
<EchoData>Hello World!!</EchoData>
</OTA_PingRS>
我在 NodeJS 的 http POST 请求中的 headers 对象的 options 变量中包含了相同的参数。 (见下面的代码)
我仍然收到以下回复:200“表单后数据中缺少‘otaRQ’!”
所以我的问题是,如何获得与 SoapUI-5.3.0 相同的响应?
非常感谢您的努力!
var http = require('http');
var body = '<OTA_PingRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="3.30" TimeStamp="2011-07-24T10:07:24" Target="Production"> <EchoData><![CDATA[Hello World!!]]></EchoData> </OTA_PingRQ>'
var postRequest = {
hostname: "cultswitch.cultuzz.de",
path: "/cultswitch/processOTA",
method: "POST",
port: 8080,
headers: {
'otaRQ': '<OTA_PingRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="3.30" TimeStamp="2011-07-24T10:07:24" Target="Production"> <EchoData><![CDATA[Hello World!!]]> </EchoData> </OTA_PingRQ>',
'Cookie': "cookie",
'Content-Type': 'text/xml',
'Content-Length': Buffer.byteLength(body)
}
};
var buffer = "";
var req = http.request( postRequest, function( res ) {
console.log( res.statusCode );
var buffer = "";
res.on( "data", function( data ) { buffer = buffer + data; } );
res.on( "end", function( data ) { console.log( buffer ); } );
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write( body );
req.end();
摘自 channel 管理提供商: 数据交换将使用标准HTTP协议(protocol)进行。这 请求消息应在名为“otaRQ”的参数中作为 POST-DATA 发送 并且回复消息将被直接写入HTTP-Response 邪教开关。 CultSwitch 仅接受“text/xml”格式的请求。邪教开关也 支持每个请求和响应的 gzip 压缩。请求系统 应该设置正确的请求 header 。发布任何内容时都必须输入“PrimaryLangID” 向 CultSwitch 请求。
最佳答案
我发现它要求您的参数名为 otaRQ。你还没有这样做。试试这个:
var body = 'otaRQ=<OTA_PingRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="3.30" TimeStamp="2011-07-24T10:07:24" Target="Production"> <EchoData><![CDATA[Hello World!!]]></EchoData> </OTA_PingRQ>'
关于javascript - NodeJS XML HTTP POST 请求 header 对象不接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42933716/