Anton Hoerl
Anton Hoerl

Reputation: 199

NodeJS XML HTTP POST request headers object not accepting

I am trying to get a Ping message back from an API of a channel manager for hotels. (XML Open Travel Alliance)

I made the HTTP XML POST request first with SoapUI-5.3.0 tool including the following parameter:

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>

and received the following XML response:

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

I included the same parameter in the http POST request in NodeJS in the options variable in the headers object. (see code below)

Still I recieve the following response: 200 "'otaRQ' is missing in post-form data!"

So my question is, how do I get the same response like with SoapUI-5.3.0?

Thanks a lot for the efforts!

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();

Excerpt from channel manager provider: The data exchange will be carried out using the standard HTTP protocol. The request message should be sent as POST-DATA within a parameter called 'otaRQ' and the reply message will be written directly into the HTTP-Response by the CultSwitch. CultSwitch accepts request in "text/xml" format only. CultSwitch also supports gzip compression for every request and response. The requesting system should set proper request headers. "PrimaryLangID" is mandatory to post any request to CultSwitch.

Upvotes: 1

Views: 686

Answers (2)

gjegadesh
gjegadesh

Reputation: 144

I see that it requires your parameter be called otaRQ. You have not done that. Try this:

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

Upvotes: 1

gjegadesh
gjegadesh

Reputation: 144

Since your error message says that you are missing post-form data, try setting your content-type header to "application/x-www-form-urlencoded".

So, 'Content-type': 'application/x-www-form-urlencoded',

Upvotes: 0

Related Questions