我正在学习Web开发的MEAN堆栈。我在客户端有以下代码:
var req = {
method: 'POST',
url: 'http://localhost:3000/Sad/3',
headers: {
'Content-Type': "Text"
},
data: {ID: Auth.sadit , UID: $scope.Sodid , PID: 1234}
};
以下是在服务器端:
app.post('/Sad/:Type', function(req, res) {
var param = req.data;
var qry = req.headers;
var url =req.url;
console.log(req.data + "\n");
if(req.params.Type == 1){
<print all the parameters in request>
}
if(req.params.Type == 3){
<Print the parameters in the request , change them and send it back>
}
res.status(200).send( " Hello User");
});
现在,当我尝试打印从客户端发送的数据中发送的参数时,我只给出了未定义的内容。
答案 0 :(得分:0)
看起来您正在向api发送json,因此content-type
应该是application/json
而不是text
。