lundi 24 juin 2019

Error when trying to make request to API using require request

Trying to make request to Google.com using code from npm require website:

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. 

I've installed request. How can I fix this?




Aucun commentaire:

Enregistrer un commentaire