Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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
Node.js Post请求正文分析错误_Node.js_Angularjs_Express_Http Post - Fatal编程技术网

Node.js Post请求正文分析错误

Node.js Post请求正文分析错误,node.js,angularjs,express,http-post,Node.js,Angularjs,Express,Http Post,我正在尝试制作一个$http.post,如下所示: $http({ method: 'POST', url: '//192.168.2.1:3000/auth/signup', data: $scope.credentials, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }) 当: 在Node中,我正在记录: 控制台日志(请求正文) 我得到: { '{"email"

我正在尝试制作一个$http.post,如下所示:

$http({
   method: 'POST',
   url: '//192.168.2.1:3000/auth/signup',
   data: $scope.credentials,
   headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
   }
})
当:

在Node中,我正在记录: 控制台日志(请求正文)

我得到:

{ '{"email":"some_email","password":"some_password"}': '' }

我不明白为什么会发生这种情况。

您假设angularjs正在为您自动序列化表单数据

在处理非json的内容类型时,您需要自己序列化表单数据


例如,当内容类型等于
'application/x-www-form-urlencoded'
时,给定一个对象
{foo:“bar”,bar:“baz”}
,它需要序列化为
foo=bar&bar=baz

您是否尝试将内容类型设置为
application/json
?您假设angular正在为您自动序列化表单数据。假设内容类型为text/xml,您必须实际发送字符串,而不是json对象。因此,实际发送表单数据字符串
数据:“foo=bar&bar=baz…”
@mpm AngularJS正在自动将数据序列化(请参阅)!@Blackhole到json,可能不是到xml或表单数据。它不会将js对象序列化到表单数据。@mpm你错了,伙计。看一看,它可以对数据本身进行简单检查,而不是对标题或其他内容进行检查。
{ '{"email":"some_email","password":"some_password"}': '' }