简体   繁体   English

带有代理的 net/http 导致 EOFError(到达文件末尾)

[英]net/http with proxy results in EOFError (end of file reached)

I'm trying to use NORD VPN proxy to make a request in ruby.我正在尝试使用 NORD VPN 代理在 ruby 中发出请求。 The proxy is good, I've tested it successfully with curl as well as in a python script.代理很好,我已经用 curl 以及 python 脚本成功地测试了它。

However, I'm not able to make it work in ruby and I suspect it has to do with the odd port (89) used in the proxy since I've done this successfully in ruby before using port 80.但是,我无法使其在 ruby 中工作,我怀疑它与代理中使用的奇数端口(89)有关,因为我在使用端口 80 之前在 ruby 中成功完成了此操作。

Any advice is welcome, hopefully you're able to point out a flaw in my code!欢迎任何建议,希望您能够指出我的代码中的缺陷!

require "uri"
require 'net/http'

proxy_host = 'no179.nordvpn.com'
proxy_port = 89
proxy_user = 'user'
proxy_pass = 'pass'

uri   = URI.parse("https://api.ipify.org/")
proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass)

req = Net::HTTP::Get.new(uri.path)

result = proxy.start(uri.host, uri.port) do |http|
  http.request(req)
end

Error:错误:

3.0.2/lib/ruby/gems/3.0.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:227:in 'rbuf_fill': end of file reached (EOFError)

As a side note I felt it worth mentioning I've tried the following http clients with the same results:作为旁注,我觉得值得一提的是,我尝试了以下 http 客户端,结果相同:

  • HTTParty (same error) HTTParty(同样的错误)
  • Faraday (same error)法拉第(同样的错误)
  • http.rb http.rb
    • 3.0.2/lib/ruby/gems/3.0.0/gems/http-5.0.4/lib/http/connection.rb:108:in 'read_headers:': couldn't read response headers (HTTP::ConnectionError)

Ruby version: 3.0.2 Ruby版本:3.0.2

I don't own a NordVPN account so I can't really test, but it looks like they are shutting down the HTTP proxies https://nordvpn.com/es/blog/removing-http-proxies/我没有 NordVPN 帐户,因此无法真正进行测试,但看起来他们正在关闭 HTTP 代理https://nordvpn.com/es/blog/removing-http-proxies/

I would suggest you to try first the SOCK proxies with this https://net-ssh.github.io/ssh/v2/api/classes/Net/SSH/Proxy/SOCKS5.html我建议您首先尝试使用此https://net-ssh.github.io/ssh/v2/api/classes/Net/SSH/Proxy/SOCKS5.ZFC35FDC70D5FC69D23EZ88888的 SOCK 代理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM