ruby - 帮助 Net::HTTP 在 Ruby 中使用身份验证

标签 ruby authentication

我正在尝试获取 Ruby 脚本以从服务器下载文件,但我从 IIS 收到 401.2:

You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.

我检查过基本身份验证是否已启用。 Ruby 处理基本身份验证的方式有什么特别之处吗?有什么方法可以让我查看服务器实际获取的内容以及 header 所说的内容是可以接受的吗?

这是我的代码:

   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
    }

最佳答案

Snippet from the Microsoft website

HTTP 401.2:服务器配置拒绝 说明

客户端浏览器和 IIS 无法就身份验证协议(protocol)达成一致。

常见原因

* 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 身份验证。

关于ruby - 帮助 Net::HTTP 在 Ruby 中使用身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1079185/

相关文章:

ruby - 如何使用 ruby​​ ffi gem 调用 Rust 库中的独立函数?

python - 是否可以将我机器上的环境变量推送到 GitHub?

java - 绕过登录屏幕

javascript - MarkLogic 应用程序服务器自定义登录页面 sessionID cookie 与 GET 请求

web-services - 在 BPEL 中获取经过身份验证的用户

sql - datetime 的值始终为 nil

ruby - 具有双高清和 "space in name"错误的 RVM

ruby-on-rails - 在 Rails 中使用 XML 发出 SOAP 请求

ruby - 在 Ruby 中,OptionParser 返回 bool 值而不是输入值

authentication - hyperledger-composer: "The current identity, with the name ' admin' 和标识符 'xxx' 尚未注册”