2015-05-19 226 views

回答

3

這是異步的。

var request = require('request'); 
console.log('1'); 
request 
    .get('http://google.com/img.png') 
    .on('response', function(response) { 
     //Happens at some time later. 
     console.log('2'); 
     console.log(response.statusCode) // 200 
     console.log(response.headers['content-type']) // 'image/png' 
    }); 
console.log('3'); 

輸出:

1 
3 
2 
404 
text/html; charset=UTF-8