Skip to content

Instantly share code, notes, and snippets.

@audstanley
Created January 13, 2016 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audstanley/7ac77bef9f2bc4234a9f to your computer and use it in GitHub Desktop.
Save audstanley/7ac77bef9f2bc4234a9f to your computer and use it in GitHub Desktop.
var Promise = require('bluebird');
var bhttp = require('bhttp');
var session = bhttp.session({ headers: {"user-agent": "MyCustomUserAgent/2.0"} });
// Our new session now automatically has a cookie jar, and also uses our preset option(s).
Promise.try(function(){
return session.get("http://admin:password2@localhost:8080/gui/"); // Assume that this site now sets a cookie
}).then(function(response){
var regex = new RegExp('<div id=(?:\'|")token(?:\'|")[^>]+>(.*)</div>');
var matches = regex.exec(response.body);
var ourToken = matches[1];
return session.get("http://admin:password2@localhost:8080/gui/token.html"); // This now sends along the cookie!
}).then(function(response) {
return console.log(response.body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment