Reputation: 167
I'm trying to use Shoes' download() method to pass a username and password in the HTTP header to authenticate the HTTP request (talking to a Rails app).
I'm a bit of a newb when it comes to this stuff.
I havn't quite understood whether I should be automatically able to use the below syntax (username:pwd@) or whether the username and password should be created manually inside the HTTP header (which I think I can also access using :headers of the download method).
download "http://username:[email protected]:3000/authenticate", :method => "POST" do |result|
# process result.response.body here
end
Any help would be appreciated
Upvotes: 3
Views: 425
Reputation: 167
Can I answer my own question?
This seems to do the trick:
require 'base64'
< ... snip ... >
# create the headers
headers = {}
headers['Authorization'] = 'Basic ' + encode64("#{@login.text()}:#{@pword.text()}").chop
# run the download
download "#{$SITE_URL}/do_something", :method => "GET", :headers => headers do |result|
@status.text = "The result is #{result.response.body}"
end
Upvotes: 2