2

我正在寻找一个“本机”支持 NTLM 代理身份验证的 ruby​​ HTTP 客户端 gem,而不是通过 cntlm 或类似的本地代理。

任何提示表示赞赏。

4

3 回答 3

2

一点挖掘出土的台风:

require 'typhoeus'
e=Typhoeus::Easy.new
e.url="http://www.google.com/"
e.proxy = {:server => "1.2.3.4:80"}
e.proxy_auth={:username => "user", :password => 'password'}
e.perform
于 2012-06-15T09:25:16.677 回答
1

You can do ntlm with Typhoeus and Ethon - depending how many features you need. Typhoeus has more than Ethon, but Ethon is more powerful as it is more low level.

require 'ethon'
easy = Ethon::Easy.new(
  url: "http://www.google.com/", 
  proxy: "1.2.3.4:80", 
  proxyuserpwd: "user:password", 
  proxyauth: "ntlm"
)
easy.perform

Typhoeus accepts the same options:

require 'typhoeus'
request = Typhoeus::Request.new(
  "http://www.google.com/", 
  proxy: "1.2.3.4:80", 
  proxyuserpwd: "user:password", 
  proxyauth: "ntlm"
)
request.run

I wrote both code examples without testing them b/c I lack a proxy and with the latest Typhoeus/Ethon versions (which you don't have already according to your example).

于 2013-07-25T22:33:54.653 回答
1

Typhoeus 似乎已被重新利用。libcurl 包装器现在是 Ethon ( https://github.com/typhoeus/ethon )。

我已经使用另一个 libcurl 包装器 Curb ( https://github.com/taf2/curb ) 成功地通过 NTLM 代理进行了身份验证:

require 'spec_helper'
require 'curl'

describe Curl do
  it 'should connect via an ISA proxy' do
    c = Curl::Easy.new('http://example.com/') do |curl|  
      curl.proxy_url = 'http://username:password@localhost:8080'
      curl.proxy_auth_types = Curl::CURLAUTH_NTLM
    end

    c.perform

    headers = c.header_str.split("\r\n")
    #puts headers.inspect

    headers.should include 'X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.19'
  end

end

根据需要更改您的设置和断言。

于 2013-07-10T14:52:31.180 回答