我正在开发一个 nodejs 项目,我使用请求模块提交安静的请求并获得响应。(这里是模块链接:https : //github.com/request/request)
按照说明,我应该能够通过调用来获取响应标头response.headers['']
,但是,似乎它不起作用,当我尝试调用时var contentType = response.headers['Content-Type']
,contentType
is undefined
。(当我使用邮递员时,我可以从响应中获取 Content-Type)。有谁知道出了什么问题?
这是网站的说明:
var request = require('request')
request(
{ method: 'GET'
, uri: 'http://www.google.com'
, gzip: true
}
, function (error, response, body) {
// body is the decompressed response body
console.log('server encoded the data as: ' + (response.headers['content-encoding'] || 'identity'))
console.log('the decoded data is: ' + body)
}
Run Code Online (Sandbox Code Playgroud)
在节点中,头是通过使用小写名称来访问的,所以使用response.headers['content-encoding']
是正确的。
您的代码片段目前适用于我并显示“服务器将数据编码为:gzip”。
归档时间: |
|
查看次数: |
14690 次 |
最近记录: |