I'm using a platform for data security, and they have this code snippet showing how to post data to their platform:
They're using the request module: https://github.com/mikeal/request
const request = require('request');
request({
url: 'https://mypass.testproxy.com/post',
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({'secret' : 'secret_value'})
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log('Status:', response.statusCode);
console.log(JSON.parse(body));
}
});
It works fine, but I wanted to replace the 'secret' : 'secret_value' object with my form data, but I'm having a hard time figuring out how to do this. The only way I know how to retrieve form data is with req.body:
function(req, res) {
var form = {
card_number: req.body.card_number,
card_cvv: req.body.cvv,
card_expirationDate: req.body.card_expirationDate,
};
// ...
});
How would I do that? Any help is greatly appreciated.
I know the code below is wrong, but that's the idea of what I want to achieve:
request( function(req, res) {
var form = {
card_number: req.body.card_number,
card_cvv: req.body.cvv,
card_expirationDate: req.body.card_expirationDate,
};{
url: 'https://mypass.testproxy.com/post',
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(form)
...```