[英]View Express JS response headers?
If I need to see the incoming request headers I use: req.headers<\/code> .
如果我需要查看我使用的传入请求标头:
req.headers<\/code> 。
I need to see the list of all headers that will be in the response.我需要查看响应中所有标题的列表。
res.headers<\/code> is
undefined<\/code> .
res.headers<\/code>
undefined<\/code> 。
I know I can set response headers:
res.header('', '')<\/code> .
我知道我可以设置响应头:
res.header('', '')<\/code> 。
How do I view the response headers..?如何查看响应标头..?
"
In recent versions of express there is: 在最近的快递版本中有:
res.getHeaders()
-> {x-powered-by: "Express"}
Properties starting with "_" are not part of the official api. 以“_”开头的属性不是官方api的一部分。 In case of changes, they will not be documented, and chances are the code will break. 如果发生变化,它们将不会被记录,并且代码可能会中断。
Also: 也:
res.get('Content-Type'); // => "text/plain"
https://expressjs.com/en/api.html#res.get https://expressjs.com/en/api.html#res.get
and, confusingly, lowercase is fine: 而且,令人困惑的是,小写很好:
res.get('content-type');
// => "text/plain"
res.getHeaders()['content-type']
// => "text/plain"
You Can This Method ...你可以用这个方法...
/* ----------------------- Get Response Header By Name ---------------------- */
/* res.getHeader('Put Header Name Here'); */
/* For Example */
res.getHeader('x-powered-by');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.