![]() |
月球上的汤圆 · 视觉格式化模型 | 杨信鹏的博客· 4 天前 · |
![]() |
豪爽的牛肉面 · Stack overflow AFTER ...· 3 天前 · |
![]() |
没人理的骆驼 · 向量存放區資料庫 - Azure AI ...· 6 月前 · |
![]() |
不拘小节的爆米花 · 杨国福集团CIO舒尚斌:以搭积木的方式考虑整 ...· 1 年前 · |
![]() |
机灵的莲藕 · 淘宝开放平台 - 文档中心· 1 年前 · |
![]() |
含蓄的消炎药 · 走进 Python 类的内部 - 掘金· 2 年前 · |
![]() |
胡子拉碴的卤蛋 · mongodb ...· 2 年前 · |
我使用的是
res.send
,不管怎样,它都会返回状态200。我希望针对不同的响应(错误等)将该状态设置为不同的数字
这是在使用
express
我假设您使用的是像"Express“这样的库,因为nodejs没有提供
res.send
方法。
与在 Express guide 中一样,您可以传入第二个可选参数来发送响应状态,例如:
// Express 3.x
res.send( "Not found", 404 );
// Express 4.x
res.status(404).send("Not found");
res.writeHead(200, {'Content-Type': 'text/event-stream'});
http://nodejs.org/docs/v0.4.12/api/http.html#response.writeHead
我将此与express一起使用
res.status(status_code).send(response_body);
而且这个没有express (普通的http服务器)
res.writeHead(404, {
"Content-Type": "text/plain"
res.write("404 Not Found\n");
res.end();