现在作为示例,我收到一个响应,其中部分键/值作为 javascript 对象:
status: '200 OK',
'content-encoding': 'gzip'
我可以通过以下方式轻松读出并记录状态消息:headers.status 但是当我尝试记录内容编码(在这种特殊情况下我需要)时,它会出错:
headers.'content-encoding' <- obviously the quotes it doesn't like
headers.content-encoding <- obviously the '-' it doesn't like
我想如何获取/读取/记录它的内容编码值?
你好,
m0rph3v5
最佳答案
Javascript 还支持用于引用属性的方括号表示法,因此如果 headers
是一个合适的对象,您可以使用 headers['content-encoding']
。
关于javascript - 使用 node.js 读取传入的 HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4546338/