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

后端 未结 2 1663
攒了一身酷
攒了一身酷 2021-02-02 14:26

Here is my code

domain = \'http://www.google.com\'
url = URI.parse \"https://graph.facebook.com/fql?q=SELECT%20url,normalized_url%20FROM%20link_stat%20WHERE%20ur         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 15:06

    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:

    #
    

提交回复
热议问题