I am trying to setup a simple node.js proxy to pass off a post to a web service (CSW in this isntance).
I'm posting XML in a request body, and specifying text/xml. -- The service requires these.
I get the raw xml text in the req.rawBody var and it works fine, I can't seem to resubmit it properly however.
My method looks like:
app.post('/csw*', function(req, res){
console.log("Making request to:" + geobusOptions.host + "With query params: " + req.rawBody);
request.post(
{url:'http://192.168.0.100/csw',
body : req.rawBody,
'Content-Type': 'text/xml'
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
});
I just want to submit a string in a POST, using content-type text/xml. I can't seem to accomplish this however!
I am using the 'request' library @ https://github.com/mikeal/request
This works great:
request.post(
{url:'http://192.168.0.100/csw',
body : req.rawBody,
headers: {'Content-Type': 'text/xml'}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
Well, I sort of figured it out eventually, to repost the body for a nodeJS proxy request, I have the following method:
request.post(
{url:'http://192.168.0.100/csw',
body : req.rawBody,
headers: {'Content-Type': 'text/xml'}
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
I get rawbody by using the following code:
app.use(function(req, res, next) {
req.rawBody = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
req.rawBody += chunk;
});
req.on('end', function() {
next();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With