【问题标题】:Ruby http client with "native" ntlm proxy support具有“本机”ntlm 代理支持的 Ruby http 客户端
【发布时间】:2012-06-15 07:42:08
【问题描述】:

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

任何提示表示赞赏。

【问题讨论】:

    标签: ruby http ntlm


    【解决方案1】:

    一点挖掘出土的台风:

    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
    

    【讨论】:

    【解决方案2】:

    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
    

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

    【讨论】:

      【解决方案3】:

      您可以使用 Typhoeus 和 Ethon 进行 ntlm - 取决于您需要多少功能。 Typhoeus比Ethon拥有更多,但Ethon更强大,因为它的级别更低。

      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 接受相同的选项:

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

      我编写了两个代码示例而没有测试它们 b/c 我缺少代理并且使用最新的 Typhoeus/Ethon 版本(根据您的示例,您还没有)。

      【讨论】:

        猜你喜欢
        • 2020-02-23
        • 1970-01-01
        • 2013-09-24
        • 1970-01-01
        • 1970-01-01
        • 2017-01-08
        • 1970-01-01
        • 2019-06-29
        • 1970-01-01
        相关资源
        最近更新 更多