发送一个包含ecoded JSON的POST请求

我正在尝试进行包含JSON编码表单的POST调用。

我为什么这样做? 我没有select,我正在工作的Facebook API,预计接收JSON编码的数据,并在接收JSON时发生错误。

我得到错误types错误TypeError: stringify expects an objectTypeError: stringify expects an object时:

 var datas = JSON.stringify({ some: "JSON" }); request.post('https://graph.facebook.com/...', { form: datas }, function(error, response, body) { //Fail before the callback call }); 

如何避免这一点?

这不是在这里失败的第一行JSON.stringify ,它是预期将是一个对象的form属性。

不要试图将其作为表单数据发送,只需将JSON文本放在请求的正文中即可。

 var datas = JSON.stringify({ some: "JSON" }); request.post('https://graph.facebook.com/...', { body: datas }, function(error, response, body) { //Fail before the callback call });