I wish to perform a POST request from my NodeJS server. It needs to send raw xml data.
What's the recommended approach for this please?
Edit: Adding my current sandbox. Not yet successful!
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser());
var data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.__DOMAIN__.com"><soapenv:Header><api:userToken><password>pwd1</password><username>usr_api</username></api:userToken></soapenv:Header><soapenv:Body><api:SearchModels><!--Optional:--><searchText>keyword</searchText></api:SearchModels></soapenv:Body></soapenv:Envelope>';
var options = {
host: 'www.__MY_END_POINT_.com', port:443,
method: 'POST',
headers: {
'Content-Type': 'text/xml',
'Content-Length': data.length
}
};
var req = http.request(options, function(res)
{
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log("body: " + chunk);
});
});
req.write(data);
req.end();
Thanks, J.