gpt4 book ai didi

对 https 的 Ruby 请求 - "in ` read_nonblock':连接由对等方重置(Errno::ECONNRESET)”

转载 作者:数据小太阳 更新时间:2023-10-29 06:36:34 25 4
gpt4 key购买 nike

这是我的代码

domain = 'http://www.google.com'
url = URI.parse "https://graph.facebook.com/fql?q=SELECT%20url,normalized_url%20FROM%20link_stat%20WHERE%20url='#{domain}'"
req = Net::HTTP::Get.new url.path
res = Net::HTTP.start(url.host, url.port) {|http| http.request req}
puts res.body

它给了我

/home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:153:in `read_nonblock': Connection reset by peer (Errno::ECONNRESET)
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:153:in `rbuf_fill'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:144:in `readline'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http/response.rb:39:in `read_status_line'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http/response.rb:28:in `read_new'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:1405:in `block in transport_request'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:1402:in `catch'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:1402:in `transport_request'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:1375:in `request'
from /home/alex/Documents/ruby_test1.rb:20:in `block in <main>'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /home/alex/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/http.rb:582:in `start'
from /home/alex/Documents/ruby_test1.rb:20:in `<main>'

我做错了什么?

最佳答案

您的代码中有几个奇怪的地方。主要是:因为你使用 SSL 你要知道 HTTP.start 关于 :use_ssl => url.scheme == 'https' . HTTP.Get 构造函数等待 URI,而不是路径。总结:

domain = 'http://www.google.com'
url = URI.parse("https://graph.facebook.com/fql?q=SELECT%20url,normalized_url%20FROM%20link_stat%20WHERE%20url='#{domain}'")
req = Net::HTTP::Get.new url
res = Net::HTTP.start(url.host, url.port,
:use_ssl => url.scheme == 'https') {|http| http.request req}
puts res

给予:

#<Net::HTTPOK:0x000000027d0558>

关于对 https 的 Ruby 请求 - "in ` read_nonblock':连接由对等方重置(Errno::ECONNRESET)”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15726744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com