快速中间件无法正确读取JSON

时间:2016-10-27 14:34:26

标签: json node.js

我正在尝试从一个节点服务器向另一个节点服务器发送带有一些JSON数据的POST请求。我正在使用JSON.stringify将对象转换为JSON并使用众所周知的request模块发布它:

request({
    url: 'https://localhost:8080/post',
    method: "POST",
    "rejectUnauthorized": false, //sending it through localhost so not worried about ssl
    json: JSON.stringify(tradeoffer)
});

JSON以良好的格式返回,但用双引号括起来。 Express'中间件模块,body-parser对此并不满意,并返回异常:Unexpected token "

如何让JSON.stringify用单引号包装我的JSON,而不是双引号。

提前致谢。

1 个答案:

答案 0 :(得分:0)

信用:katy lavalle在评论中。

请求模块将为您完成:

request({
    url: 'https://localhost:8080/post',
    method: "POST",
    "rejectUnauthorized": false, //sending it through localhost so not worried about ssl
    json: tradeoffer
});
相关问题