简体   繁体   中英

https request return 'getaddrinfo ENOTFOUND'

In my server web application after using Oauth2.0 i got a accessToken.Futher i want to use the accesToken and get list of files in my google drive.

GET /drive/v2/files HTTP/1.1 Authorization: Bearer access_token
Host: www.googleapis.com/

Here is my code

 const https = require('https'); const options = { 'host': 'www.googleapis.com/', 'path': '/drive/v2/files', 'method': 'GET', 'headers': { 'Authorization': 'Bearer <access-token>' } } https.request(options, res => { console.log(res); }); 

But i'm getting

Error: getaddrinfo ENOTFOUND www.googleapis.com/

const https = require('https');

const options = {
  host: 'www.googleapis.com',
  path: '/drive/v2/files',
  method: 'GET',
  headers: {
    'Authorization': 'Bearer <access-token>'
  }
}
const req = https.request(options, res => {
    console.log('Status Code:',res.statusCode);
    console.log('headers:',res.headers);

    res.on('data',(d)=>{
        process.stdout.write(d);
    })
});

req.on('error', (e) => {
  console.error(e);
});
req.end();

reference link: https://nodejs.org/api/https.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM