2009-07-03 46 views
2

我試圖讓Ruby腳本下載文件時關閉服務器,但我發現從IIS中的401.2:幫助得到的Net :: HTTP與認證工作在Ruby中

你不有權查看 此目錄或頁面使用您提供的 憑據,因爲您的Web瀏覽器正在發送 WWW-Authenticate標頭字段,該 Web服務器未配置爲 接受。

我檢查過啓用了基本身份驗證。關於Ruby如何處理基本身份驗證有什麼特別之處?有沒有一種方法可以讓我看到服務器實際獲得的內容以及頭文件可接受的內容?

這是我的代碼:

Net::HTTP.start(url, port) {|http| 
     req = Net::HTTP::Get.new('/file.txt') 
     req.basic_auth 'username', 'password' 
     response = http.request(req) 
     puts response.body 
    } 

回答

1

Snippet from the Microsoft website

HTTP 401.2:由服務器配置 說明

客戶端瀏覽器和IIS拒絕上的身份驗證協議不能同意。

常見原因

* No authentication protocol (including anonymous) is selected in IIS. At least one authentication type must be selected. For more information, click the following article number to view the article in the Microsoft Knowledge Base: 
    253667 (http://support.microsoft.com/kb/253667/) Error message: HTTP 401.2 - Unauthorized: Logon failed due to server configuration with no authentication 
* Only Integrated authentication is enabled, and an older, non-Internet Explorer client browser tries to access the site. This happens because the client browser cannot perform Integrated authentication. To resolve this problem, use one of the following methods: 
     o Configure IIS to accept Basic authentication. This should only occur over SSL for security purposes. 
     o Use a client browser that can perform Integrated authentication. Internet Explorer and new versions of Netscape Navigator and Mozilla Firefox can perform Integrated authentication. 
* Integrated authentication is through a proxy. This happens because the proxy doesn't maintain the NTLM-authenticated connection and thus sends an anonymous request from the client to the server. Options to resolve this problem are as follows: 
     o Configure IIS to accept Basic authentication. This should only occur over SSL for security purposes. 
     o Don't use a proxy. 

你也應該嘗試一下ruby-httpclient - Simple HTTPClient library for Ruby可同時使用NTLM身份驗證。

+1

我認爲這是ruby-httpclient的正確網址:https://rubygems.org/gems/httpclient。 – hughdbrown 2012-06-22 20:48:37