Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
request node.js模块可以';Don’不要发简单的邮件_Node.js_Http_Post - Fatal编程技术网

request node.js模块可以';Don’不要发简单的邮件

request node.js模块可以';Don’不要发简单的邮件,node.js,http,post,Node.js,Http,Post,我这样发送: var url = "http://localhost:9001/v1/sanger/auth/facebook/callback", options = {body: JSON.stringify(params), 'Content-type': 'application/json'}; request.post(url, options, function (error, response, body) { ... callbacks ..

我这样发送:

var url     = "http://localhost:9001/v1/sanger/auth/facebook/callback",
    options = {body: JSON.stringify(params), 'Content-type': 'application/json'};

    request.post(url, options, function (error, response, body) {
      ... callbacks ... 
    });
我没有在路由中获取参数(已尝试
body
params
query

当我使用postman()时,我在
req.body

中得到它,这是一种更好的方法(我假设您已经在其他地方初始化了
参数
变量):

您无法获取
正文
,因为当您调用
JSON.stringify(params)
时,您正在将
params
转换为字符串,并且不再有
JSON
对象。如果您以
纯文本
的形式发送信息,但告诉
请求
您想要
json
,您的express应用程序无法验证
内容类型
,可以通过以下方式进行检查:

request.get('Content-Type'); // returns undefined
因为您需要一个
json
对象,所以不应该这样做。只需传递
json
对象,如上面的示例所示

然后,在路由代码中,您可以执行
req.body
req.param('a_param')
(对于
json
的特定键)来获取这些值

request.get('Content-Type'); // returns undefined