npm request with headers and auth npm request with headers and auth curl curl

npm request with headers and auth


Here is how it worked for me

 var auth = new Buffer(user + ':' + pass).toString('base64'); var req = {     host: 'https://XXX/index.php?/api/V2/get_case/2',     path: path,     method: 'GET',     headers: {         Authorization: 'Basic ' + auth,         'Content-Type': 'application/json'     } };


request(url, {  method: "POST",  auth: {    user: this.user,    pass: this.pass  }}, function (error, response, body) {    if (!error && response.statusCode == 200) {      console.log('body:', body);    } else {      console.log('error', error, response && response.statusCode);    }});