3

我正在尝试使用 Shoes 的 download() 方法在 HTTP 标头中传递用户名和密码来验证 HTTP 请求(与 Rails 应用程序通信)。

当谈到这些东西时,我有点新手。

我不太明白我是否应该能够自动使用以下语法(用户名:pwd@),或者是否应该在 HTTP 标头中手动创建用户名和密码(我想我也可以使用 :headers 的下载方法)。

download "http://username:pwd@127.0.0.1:3000/authenticate", :method => "POST" do |result| 
     # process result.response.body here
end

任何帮助,将不胜感激

4

1 回答 1

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
于 2008-11-11T05:39:01.143 回答