How to use node-libcurl with NETRC option

111 Views Asked by At

I need to make an HTTP GET using curl with netrc file with auth credentials. But I think that I'm doing something brong because I get an HTTP 200 RESPONSE but in the body there is the HTML for the authentication page of the site.

This is the code that I made:

const { Curl } = require('node-libcurl');

async function start() {
    const curl = new Curl();

    curl.setOpt('URL', 'https://cddis.nasa.gov/archive/gps/data/highrate/2022/331/22d/00/ABMF00GLP_S_20223310000_15M_01S_MO.crx.gz');
    curl.setOpt('FOLLOWLOCATION', true);
    curl.setOpt('NETRC', true);
    curl.setOpt('NETRC_FILE', '.netrc');
    curl.setOpt('MAXREDIRS', 5);
    curl.setOpt('SSL_VERIFYPEER', false);
    curl.setOpt('SSL_VERIFYHOST', false);
    
    curl.on('end', function (statusCode, data, headers) {
      console.info(statusCode);
      console.info('---');
      console.info(data.length);
      console.info('---');
      console.info(data);
      console.info('---');
      console.info(this.getInfo( 'TOTAL_TIME'));
      
      this.close();
    });

    curl.on('error', curl.close.bind(curl));
    curl.perform();
}

start();

And the .netrc file is in the same directory that the code. This content is:

machine urs.earthdata.nasa.gov login <username> password <password>

Thanks so much!

0

There are 0 best solutions below