Reputation: 5280
I am trying to make a POST call containing a JSON encoded form.
Why am i doing that ? I have no choice, i am working the the Facebook API which expects to receive a JSON encoded data and fire an error when receiving JSON.
I get the error TypeError: stringify expects an object
when doing:
var datas = JSON.stringify({ some: "JSON" });
request.post('https://graph.facebook.com/...', { form: datas }, function(error, response, body) {
//Fail before the callback call
});
How to avoid that ?
Upvotes: 1
Views: 499
Reputation: 29999
It is not the JSON.stringify
in the first line that fails here, it is the form
property which is expected to be an object.
Don't try to send it as form data, just put the JSON text in the body of the request.
var datas = JSON.stringify({ some: "JSON" });
request.post('https://graph.facebook.com/...', { body: datas }, function(error, response, body) {
//Fail before the callback call
});
Upvotes: 4