2012-06-15 63 views

回答

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 
+0

此外,这是一个非常好的Typhoeus备忘单:http://cheat.errtheblog.com/s/typhoeus/ – Konrads

+0

不幸的是Err的备忘单不再可用。 –

+1

Wayback机器仍然有它http://web.archive.org/web/20121020085404/http://cheat.errtheblog.com/s/typhoeus/ – Konrads

0

百头巨怪似乎已经改变用途。 libcurl包装器现在是Ethon(https://github.com/typhoeus/ethon)。

我已经成功地使用路边(https://github.com/taf2/curb)的NTLM代理,其他的libcurl包装认证:

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:[email protected]: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 
要求

更改设置和断言。

0

你可以用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 

百头巨怪接受相同的选项:

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我缺乏的代理,并用最新的百头巨怪/ Ethon版本(你没有已经根据你的例子)。

相关问题