Using shoe upload () for basic HTTP authentication

I am trying to use the download () method to load the username and password in an HTTP header to authenticate an HTTP request (talking to a Rails application).

I'm a little new when it comes to this.

I did not understand if I should automatically use the syntax below (username: pwd @), or if the username and password need to be created manually inside the HTTP header (which I think I can access with: the 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

+3
source share
1 answer

Can I answer my question?

This seems like a 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
+2
source

Source: https://habr.com/ru/post/1699396/


All Articles