尝试使用npm中的代码向Google.com发出请求,网址为:
var request = require('request');
request('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
}); , but receiving this error:
error: { Error: getaddrinfo ENOTFOUND www.google.com www.google.com:80
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'www.google.com',
host: 'www.google.com',
port: 80 }
statusCode: undefined
body: undefined.
我已经安装了请求。我怎样才能解决这个问题?