저는 nodejs 프로젝트에서 작업하고 있습니다. 요청 모듈을 사용하여 편안한 요청을 제출하고 응답을받습니다. 내가 var contentType = response.headers['Content-Type']
를 호출 할 때, 나는 contentType
이 undefined
이다, 그러나 그것은 작동하지 않는 것, response.headers['']
를 호출하여 응답 헤더를 얻을 수 있어야 지시에 따라node.js에서 응답 헤더를 얻는 방법
: (https://github.com/request/request 여기에 모듈 링크입니다) . (내가 우편 배달부를 사용할 때 응답에서 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)
}
코드는 콘텐츠 인코딩을 말하고 질문은 콘텐츠 유형을 말합니다. 소문자가 사용되는 한 여기에서 모두 작동합니다. –