I want to POST some JSON to my REST-Server.
The JSON looks like that:
{
"name": "John Doe",
"socials": {
"facebook": {
"uid": "1234321",
"fbsrCookie": "sdfsdfhgsd"
}
}
}
The POST-Call in Ember looks like that:
Ember.$.post('http://localhost:3000/register', data).then(function ...
Inspecting the Message with the Developer-Tools of Firefox show me that the parameters are the following
name: "John Doe"
socials[facebook][uid]: "1234321"
socials[facebook][fbsrCookie]: "sdfsdfhgsd"
Because of the Header "Content-Type" which is "application/x-www-form-urlencoded; charset=UTF-8" I cant handle with the values as objects on my node.js-backend (since its not JSON).
Is there a way a to read the properties from the server-(node.js)-backend? Or how can I send the payload as JSON?
Okay, like @sdgluck mentioned, the express.js-Framework (which Im using) can also parse the form-data (url-encoded)parameters decribed in my question above. So I double checked the including of the bodyParser-middleware of express.js and changed the "extended"-Parameter to true like so:
app.use(bodyParser.urlencoded({
extended: true
}));
Now express.js also parse the parameters and let me access them via dot-notation (like so: req.body.socials.facebook.uid
).
Thanks to @sdgluck !
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments