3

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:pwd@127.0.0.1:3000/authenticate", :method => "POST" do |result| 
     # process result.response.body here
end

Any help would be appreciated

Etienne
  • 167
  • 1
  • 1
  • 6

1 Answers1

2

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
Etienne
  • 167
  • 1
  • 1
  • 6
  • I believe you can answer your own question but it needs a certain number of upvotes before you can select it. There's also a batch for answering your own. Bravo! – mwilliams Nov 11 '08 at 12:38
  • Voting back up, since this works in Shoes (Both Shoes 2 and latest code). Verified on Windows XP. Here is _why's answer to the question from @blog: http://thread.gmane.org/gmane.comp.lib.shoes/2455/focus=2456. – atomicules Jan 18 '10 at 14:45