我正在处理一个nodejs项目,我使用request模块提交restful请求并获取响应。(这是该模块的链接:https://github.com/request/request)
根据说明,我应该通过调用
这是网站上的说明:
根据说明,我应该通过调用
response.headers['']
来获取响应头。然而,当我尝试调用var contentType = response.headers['Content-Type']
时,contentType
是undefined
。(当我使用postman时,我可以从响应中获取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)
}