gpt4 book ai didi

ruby-on-rails - ruby 网 :HTTP SSL bug or is it me?

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

我正在尝试下载 https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/174043_1701680_6450592_q.jpg使用 ruby​​,但出现连接重置错误。它在浏览器中可以正常下载,但在 Ruby 中却不行。这是 Ruby 中的错误吗? Facebook 的错误?

这适用于大多数其他 Facebook 用户。我使用的是 Ruby 1.8.7 和 Rails 2.3.11。

>> http = Net::HTTP.new("graph.facebook.com", Net::HTTP.https_default_port)
=> #<Net::HTTP graph.facebook.com:443 open=false>
>> http.use_ssl = true
=> true
>> http.start do |http|
?> response = Net::HTTP.get_response(URI.parse('https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/174043_1701680_6450592_q.jpg'))
>> end
warning: peer certificate won't be verified in this SSL session
Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.
from c:/Ruby187/lib/ruby/1.8/net/protocol.rb:135:in `sysread'
from c:/Ruby187/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
from c:/Ruby187/lib/ruby/1.8/timeout.rb:67:in `timeout'
from c:/Ruby187/lib/ruby/1.8/timeout.rb:101:in `timeout'
from c:/Ruby187/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
from c:/Ruby187/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from c:/Ruby187/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:2017:in `read_new'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:1051:in `request'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:948:in `request_get'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:380:in `get_response'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:543:in `start'
from c:/Ruby187/lib/ruby/1.8/net/http.rb:379:in `get_response'
from (irb):5
from c:/Ruby187/lib/ruby/1.8/net/http.rb:543:in `start'
from (irb):4>>

最佳答案

这是一个稍微修改过的版本...

require 'uri'
require 'net/https'

url = URI.parse 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/174043_1701680_6450592_q.jpg'
http = Net::HTTP.new url.host, url.port
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true

http.start do |agent|
p agent.get(url.path).read_body.length
end

然后……

    so ross$ ruby fbi    1974

关于ruby-on-rails - ruby 网 :HTTP SSL bug or is it me?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5721535/

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