2013-04-05 28 views
5

SSL yoluyla Imgur API'ye bağlanmaya çalışmak bana bir hata veriyor.SSL HTTP POST Hatası (Bilinmeyen Protokol)

API_URI = URI.parse('https://api.imgur.com') 
    API_PUBLIC_KEY = 'Client-ID --' 

    ENDPOINTS = { 
    :image => '/3/image', 
    :gallery => '/3/gallery' 
    } 

    # Public: Upload an image 
    # 
    # args - The image path for the image to upload 
    # 
    def upload(image_path) 
    http = Net::HTTP.new(API_URI.host) 
    http.use_ssl = true 
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE 

    params = {'image' => File.open(image_path)} 
    request = Net::HTTP::Post.new(API_URI.request_uri) 
    request.set_form_data(params) 
    request.add_field('Authorization', API_PUBLIC_KEY) 

    response = http.request(request) 
    puts response.body 
    end 

Ve hata:

`connect': SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol (OpenSSL::SSL::SSLError) 

Ben VERIFY_NODE iyi bir uygulama değil biliyorum ama sadece şimdilik bağlantısını test etmek istiyorum İşte kod ve hata var.

Yakut sürümü: 1.9.2

cevap

15

bu sorunu sabit HTTP istemcisi oluştururken noktasını belirtme. Bir http sunucusu başlamıştı çünkü benim için

http = Net::HTTP.new(API_URI.host, API_URI.port) 

veya

http = Net::HTTP.new(API_URI.host, 443) 
0

oldu (tcp: //) sunucularının yerine https (ssl: //).

yani

bundle exec puma config.ru -b 'tcp://0.0.0.0:3456?key=/path/to/key.key&cert=/path/to/cert.crt' 

yerine:

bundle exec puma config.ru -b 'ssl://0.0.0.0:3456?key=/path/to/key.key&cert=/path/to/cert.crt'