|
|
细心的毛巾 · 苹果 iPad 10 新品发布后,老款 ...· 10 月前 · |
|
|
难过的楼梯 · 杭州二中教育集团盘点!谁才是“亲儿子”?|实 ...· 1 年前 · |
|
|
文武双全的楼房 · 如何区分爵士乐下各种细分的种类? - 知乎· 2 年前 · |
|
|
爽快的小摩托 · Disney+巨亏 80 ...· 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();
|
|
文武双全的楼房 · 如何区分爵士乐下各种细分的种类? - 知乎 2 年前 |