尝试使用require请求向API请求时出错

时间:2019-06-24 15:30:26

标签: html web

尝试使用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. 

我已经安装了请求。我怎样才能解决这个问题?

0 个答案:

没有答案