【发布时间】:2019-06-08 00:33:36
【问题描述】:
我正在尝试处理来自我的 node/express 的各种 http 状态代码并将响应传递回 angular。我收到一个错误,即在将标头发送到客户端后无法设置标头。我如何根据响应处理这个问题并在 nodejs 中记录各种 http 代码?
app.post("/employees", function(req,res) {
var ServerOptions = {
method: 'POST',
uri: 'http://localhost:5001/api/empData',
body: req.body,
json: true,
headers: {
'Content-Type': 'application/json'
}
};
request(ServerOptions).then(function (Response) {
res.status(200).json(response);
})
.catch(function (err) {
res.status(401).json({message: "unauthorized"});
console.log("Unauthorized");
res.status(404 || 500).json({message: "error"});
console.log("Error");
res.set("Connection", "close");
});
});
【问题讨论】:
-
请求函数返回什么??请给我们完整的代码或者请描述请求函数是做什么的??
标签: node.js express mean-stack