Ruby Request to Https - "In 'Read_Nonblock': Connection Reset by Peer (Errno::Econnreset)"

Ruby request to https - in `read_nonblock': Connection reset by peer (Errno::ECONNRESET)

There are several oddities in your code. The main is: since you use SSL you are to aknowledge HTTP.start about with :use_ssl => url.scheme == 'https'. HTTP.Get constructor awaits for an URI, not the path. The summing up:

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

Gives:

#<Net::HTTPOK:0x000000027d0558>

Shopify Theme Ruby Gem Errors

This was an issue with the way ruby was installed on my Mac. After installing a new hard drive I installed RVM and Homebrew and everything worked fine.

Error while using Net::HTTP GET request

I believe the issue here is you're using an HTTP library to access an HTTPS service. These are fundamentally different things. Here's an HTTPS example:

require 'net/http'
require 'net/https'
http = Net::HTTP.new('www.example.com', 443)
http.use_ssl = true
http.ssl_version = :TLSv1
http.ciphers = "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:-LOW"
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
req = Net::HTTP::Get.new('/', {'Content-Type' =>'application/json'})
http.start {|http| http.request(req) }


Related Topics



Leave a reply



Submit