I am using npm Request module to make a post request. I am able to send headers but not the body.
As per documentation they have mentioned the way how to add headers, but not the way how to add headers+body.
Here is my code:
const functions = require('firebase-functions');
const cors = require('cors');
var requestz = require('request');
var makeRequest = function makeRequest(request, response){
var formData = {
bulkFileValue: "WyI5MjMyMzE0OTQ3NTYixxxxTciLCI5MjMwNTIyNzM1NzUiLCI5MjMyMTE0OTQ3NTkiLCI5MjMyMTQyODYzNzQiLCI5MjMyMTE0OTQ3Nxxxx0OTQ3NjIiLxxE0OTQ3NjMiLCI5MjMyMTE0OTQ3NjQiLCI5MjMxxQ3NjUiLCI5MjMyMTE0OTQ3NjYiXQ==",
applicationVersion: "1.0",
username: 'axxxz@fxxxxa.pk', password: 'Wxxxxedxxx3'
}
var options = {
url: 'http://newxxxxxapi.fxxxxca.web.pk/UploxxxxxkEx',
headers: {
'Content-Type':'application/x-www-form-urlencoded',
'appKey':'dNExxxxxARypxxxxnLG',
'appId':'2xxxxx7'
},
formData: formData
};
function callback(error, resp, body) {
if (!error && resp.statusCode == 200) {
var info = JSON.parse(body);
console.log(info);
response.send(info);
}
}
requestz.post(options, callback);
}
exports.processPayroll = functions.https.onRequest((request, response) => {
var corsFn = cors();
corsFn(request, response, function() {
makeRequest(request, response);
})
});
In the above code i am trying to send data/body as formData. But i think that is not the right way.
Please help me out with this as body/formData is not receiving on other end.