2
我有一些node.js代碼,我試圖從raw.github.com獲取package.info。我正在做一個HTTPS請求,但由於某種原因,它看起來像回調永遠不會被調用,因爲'here'永遠不會被輸出。爲什麼不調用https.request回調?
有沒有人看到發生了什麼問題?
console.log(options)
req = https.request(options, function(res) {
console.log('here')
res.setEncoding('utf8')
// ... more code here
})
console.log(req)
// .. return -> listening and waiting
輸出
{ host: 'raw.github.com',
port: 443,
path: '/jasny/bootstrap/2.2.2-j3-wip/package.json',
method: 'GET' }
{ domain: null,
_events:
{ response: { [Function: g] listener: [Function] },
socket: { [Function: g] listener: [Function] } },
_maxListeners: 10,
output: [],
outputEncodings: [],
writable: true,
_last: false,
chunkedEncoding: false,
shouldKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_hasBody: true,
_trailer: '',
finished: false,
agent:
{ domain: null,
_events: { free: [Function] },
_maxListeners: 10,
options: {},
requests: {},
sockets: { 'raw.github.com:443': [Object] },
maxSockets: 5,
createConnection: [Function: createConnection] },
socketPath: undefined,
method: 'GET',
path: '/jasny/bootstrap/2.2.2-j3-wip/package.json',
_headers: { host: 'raw.github.com' },
_headerNames: { host: 'Host' }
}
對於完整的代碼見lib/packageinfo.js。該函數被調用index.js