I am trying to make a WebAPI call from server script and i am getting authentication error:
This is how my server.js looks like:
var app = require('http').createServer()
, io = require('socket.io').listen(app)
, fs = require('fs')
, moment = require('moment')
, request = require('request'); //https://github.com/mikeal/request
app.listen(8000, function () {
console.log('server started');
doSomethingOnServerStart();
});
function doSomethingOnServerStart()
{
console.log('Getting something from server');
request.get({
url: 'http://localhost:63213/Api/MyAPI/GetSomething',
},
function (error, response, body) {
console.log(response.statusCode);
if (response.statusCode == 200) {
console.log('data received from server');
} else {
console.log('error: ' + response.statusCode);
console.log(body);
}
});
}
I am using Mikeal's Request library to make the WebAPI call. In the HTTP Authentication section (https://github.com/mikeal/request#http-authentication), it says pass username and password as "hash" but does not say how do i generate that hash.
I am kind of stuck and dont know how to proceed.