T
T
TempUserMain2014-05-17 23:54:36
JavaScript
TempUserMain, 2014-05-17 23:54:36

Authorization when using the "request" module in Node.js

There is a local TeamCity server.
It is required to get information from the internal page of the server.
To get information, use the request module for Node.js :

var fs = require('fs')
var request = require('request');

request.get('адрес сервера>/login.html').auth('<корректный логин>', '<корректный пароль>', false);

request('<адрес интересующей страницы>').pipe(
    fs.createWriteStream('<txt-файл, в который записывается текст с рассматриваемой страницы>')
)

However, when running the code, an error is written to the txt file:
" "Authorization" header is not specified
To login manually go to "/login.html" page "
Please tell me how to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
buzzi888, 2014-05-18
@TempUserMain

See how authorization is done here:
github.com/gogobot/teamcity-radiator/blob/master/t...

var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
  
var request = client.request('GET', "/httpAuth/app/rest" + path, {'host': base_url, 'Authorization': auth});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question