1

我创建了一个要点,它准确地显示了发生的事情。
https://gist.github.com/4418148
我测试了一个使用 ruby​​ 的 'net/http' 库和 'socksify/http' 的版本,它运行良好,但如果 EventMachine 版本返回意外结果。
Tor 浏览器中的响应是正确的,但使用 EventMachine 是不正确的!

它返回一个响应,但它与通过浏览器发送请求时返回的响应不同,net/http 有或没有代理。

为了方便,我也贴在这里。

require 'em-http-request'

DEL = '-'*40
@results = 0

def run_with_proxy
  connection_opts = {:proxy => {:host => '127.0.0.1', :port => 9050, :type => :socks5}}
  conn = EM::HttpRequest.new("http://www.apolista.de/tegernsee/kloster-apotheke",       connection_opts)
  http = conn.get
  http.callback {
    if http.response.include? "Oops"
      puts "#{DEL}failed with proxy#{DEL}", http.response
    else
      puts "#{DEL}success with proxy#{DEL}", http.response
    end
    @results+=1
    EM.stop_event_loop if @results == 2
  }
end

def run_without_proxy
  conn = EM::HttpRequest.new("http://www.apolista.de/tegernsee/kloster-apotheke")
  http = conn.get
  http.callback {
    if http.response.include? "Oops"
      puts "#{DEL}failed without proxy#{DEL}", http.response
    else
      puts "#{DEL}success without proxy#{DEL}", http.response
    end
    @results+=1
    EM.stop_event_loop if @results == 2
  }
end

EM.run do
  run_with_proxy
  run_without_proxy
end

感谢任何澄清。

4

0 回答 0