gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 16:40:01 25 4
gpt4 key购买 nike

我正在尝试获取 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com