2008-11-11 112 views
3

我試圖使用Shoes的download()方法在HTTP頭中傳遞用戶名和密碼來驗證HTTP請求(與Rails應用程序交談)。使用Shoes的下載()進行基本的HTTP身份驗證

我對這個東西有點新鮮感。

我很不理解我是否應該自動地使用下面的語法(用戶名:pwd @)或者是否應該在HTTP標頭內手動創建用戶名和密碼(我認爲我也可以使用:下載方法的標題)。

download "http://username:[email protected]:3000/authenticate", :method => "POST" do |result| 
    # process result.response.body here 
end 

任何幫助,將不勝感激

回答

2

我可以回答我的問題?

這似乎這樣的伎倆:

  require 'base64' 

< ...喀嚓...>

  # 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 
+0

我相信你能回答自己的問題,但它需要之前一定數量upvotes的你可以選擇它。還有一批用於回答你自己的問題。好樣的! – mwilliams 2008-11-11 12:38:23