3

Rest Client可以进行 NTLM 身份验证吗?

我在文档中没有看到身份验证类型的任何选项:

require 'rest_client'

resource = RestClient::Resource.new 'http://website', :auth_type => 'ntlm', :user => 'USERNAME', :password => 'PASSWORD'
results = resource.get

:auth_type => 'ntlm' 不起作用,我在文档或 IRC 房间也找不到任何东西。

4

2 回答 2

2

NTLM 要求确实缩小了您可以使用的 HTTP 软件的范围,因为它是针对 Microsoft 的。

您可能想查看“ NTLM Authentication for Ruby with Typhoeus and Curl ”,然后研究使用Typhoeus而不是 rest-client。

于 2010-11-09T00:07:37.430 回答
0

从技术上讲,您可以使用 before_execution_proc 参数来实现它,它允许您访问内部 Net::HTTP 请求对象。如果您使用的是 ruby​​-ntlm gem,它会向 Net::HTTP 请求添加一个 ntlm_auth 方法。

require 'ntlm/http'
require 'rest-client'
require 'json'

# Quick monkey patch to rest client payloads since for some reason Net/NTLM insists on playing payload streams backwards.
class RestClient::Payload::Base
  def rewind
    @stream.rewind
  end
end

auth_proc = ->(req, _args){ req.ntlm_auth(username, domain, password)}
res = RestClient::Request.new(method: :post, url: url, payload: payload}, before_execution_proc: auth_proc ).execute
res
于 2019-12-02T14:43:57.333 回答