nodejs using url + xml data post Request and get response

3,172 views
Skip to first unread message

vinodh kumar Bandaru

unread,
Feb 14, 2016, 2:34:11 PM2/14/16
to nodejs
Nodejs using "url + xml" Data post request And get Response

THis is MY PHP Code : -


 
<?php
$request
='<Request><Head><Username>0f4dd0ce77dc24f9f5e9057b6b978621</Username><Password>v0Auj1TCfQdD</Password><RequestType>HotelSearch</RequestType></Head><Body><CityId>248245</CityId><CheckInDate>2016-05-05</CheckInDate><CheckOutDate>2016-05-07</CheckOutDate><Rooms><Room><NumAdults>2</NumAdults></Room></Rooms><Nationality>US</Nationality><Currency>USD</Currency></Body></Request>';
$ch
= curl_init();
curl_setopt
($ch, CURLOPT_URL, "http://xml.travellanda.com/xmlv1");
curl_setopt
($ch, CURLOPT_TIMEOUT, 180);
curl_setopt
($ch, CURLOPT_HEADER, 0);
curl_setopt
($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt
($ch, CURLOPT_POST, 1);
curl_setopt
($ch, CURLOPT_POSTFIELDS, array('xml' => $request));
$response
= curl_exec($ch);
$info
= curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close
($ch);
echo $response
;
?>



Its work Fine. As the Same way i do in Node js.

MY Nodejs Coding : -


exports
.Travel = function(req, res){
     
var https = require('https');
   
var term = req.params.name;
   
var request = require('request');


var body = '<?xml version="1.0" encoding="utf-8"?><Request><Head><Username>0f4dd0ce77dc24f9f5e9057b6b978621</Username><Password>v0Auj1TCfQdD</Password><RequestType>HotelSearch</RequestType></Head><Body><CityId>248245</CityId><CheckInDate>2016-05-05</CheckInDate><CheckOutDate>2016-05-07</CheckOutDate><Rooms><Room><NumAdults>2</NumAdults></Room></Rooms><Nationality>US</Nationality><Currency>USD</Currency></Body></Request>'
       
 
var options = {

            url
: 'https://xml.travellanda.com/xmlv1',
             port
: 443,
             method
: 'POST',
             body
: body,
             strictSSL
: false,
            headers
: {
               
Accept: 'text/xml',
                 
'Content-Length': Buffer.byteLength(body)


           
},
         
};
 options
.agent = new https.Agent(options);
     
      request
.get(options, function(response){
       
//console.log("options.agent..", response);
         
var buffer = response.cert.raw;


       
       
const buf = new Buffer(buffer, 'utf8');
       
const json = buf.toString('UTF-8',0,5) //JSON.stringify(buf);
        res
.send(json);


       
const copy = JSON.parse(json, (key, json) => {
         
return json && json.type === 'Buffer'
           
? new Buffer(json.data)
           
: json;
       
});
       
})
}
it Show the Error Hostname/IP doesn't match certificate's altnames Please Help me
Reply all
Reply to author
Forward
0 new messages