Wie mache ich Auth in node.js Client
Ich möchte diesen Rest API mit Authentifizierung verwenden. Ich versuche, Header einzuschließen, erhalte aber keine Antwort. Es löst eine Ausgabe aus, die im Allgemeinen ausgelöst wird, wenn keine Authentifizierung vorliegt. kann mir jemand einige lösungen vorschlagen. Unten ist mein Code
var http = require('http');
var optionsget = {
host : 'localhost', // here only the domain name
port : 1234,
path:'/api/rest/xyz',
headers: {
'Authorization': 'Basic ' + new Buffer('abc'+ ':' + '1234').toString('base64')
} ,
method : 'GET' // do GET
};
console.info('Options prepared:');
console.info(optionsget);
console.info('Do the GET call');
var reqGet = http.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
console.info('GET result:\n');
process.stdout.write(d);
console.info('\n\nCall completed');
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});