2012-06-15 69 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版本(你沒有已經根據你的例子)。

相關問題