我正在使用 res.send
无论如何,它都会返回 200 的状态。我想为不同的响应(错误等)将该状态设置为不同的数字
这是使用 express
最佳答案
在发送之前添加响应头,可以使用setHeader方法:
response.setHeader('Content-Type', 'application/json')
状态only由status方法:
response.status(status_code)
两者同时使用writeHead方法:
response.writeHead(200, {'Content-Type': 'application/json'});
关于node.js - 如何使用 Node.js/Express 发回响应 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7676264/