Skip to content

Instantly share code, notes, and snippets.

@ebot
Created March 21, 2012 19:53
Show Gist options
  • Save ebot/2152056 to your computer and use it in GitHub Desktop.
Save ebot/2152056 to your computer and use it in GitHub Desktop.
Nodejs script that is the simplest possible way to log into a remote server with basic authentication.
http = require("http")
uname = "uname"
pword = "pword"
options =
host: "server_name_or_ip"
port: 80
path: "/path/to/page.aspx"
headers:
Authorization: "Basic " + new Buffer(uname + ":" + pword).toString("base64")
request = http.get(options, (res) ->
body = ""
res.on "data", (data) ->
body += data
res.on "end", ->
console.log body
res.on "error", (e) ->
console.log "Got error: " + e.message
)
var http = require('http');
var uname = 'uname';
var pword = 'pword';
var options = {
host: 'server_name_or_ip',
port: 80,
path: '/path/to/page.aspx',
headers: {
'Authorization': 'Basic ' + new Buffer(uname + ':' + pword).toString('base64')
}
};
request = http.get(options, function(res){
var body = "";
res.on('data', function(data) {
body += data;
});
res.on('end', function() {
console.log(body);
})
res.on('error', function(e) {
console.log("Got error: " + e.message);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment