tags:

views:

218

answers:

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:[email protected]:3000/authenticate", :method => "POST" do |result| 
     # process result.response.body here
end

Any help would be appreciated

+1  A: 

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
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
Voted down on your request.
Jonas Elfström
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.
i5m
A: 

Can someone vote down my answer to my own question ?..... the header code works in other libs, but not in Shoes (at least not in the version at the time of writing).

A: 

Vote down requires 100 score :P eheh Sorry