samedi 7 mars 2015

Send json data to nodejs server

I have a problem sending json data to my node server


I tried



var req = {
method: 'POST',
url: 'http://ift.tt/1we4uWX',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
},
data: {test:"test"}
};


when I console.log() req.body y have



{ '{"test":"test"}': '' }


When I try with



var req = {
method: 'POST',
url: 'http://ift.tt/1we4uWX',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
},
data: 'test=test'
};


I have a good result on the server


I set the content type to application/x-www-form-urlencoded to allow the cross domain


On the server I have



app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));


Thanks for the help


Aucun commentaire:

Enregistrer un commentaire