2013-04-05 4 views
5

SSL을 통해 Imgur API에 연결하려고하면 오류가 발생합니다.HTTP POST (알 수없는 프로토콜)에서 SSL 오류가 발생했습니다.

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 

그리고 오류 :

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

내가 VERIFY_NODE 좋은 방법이 아닙니다 알고 있지만 난 그냥 지금 연결을 테스트하려면 다음 코드와 오류입니다.

루비 버전 : 1.9.2

답변

15

이 문제를 해결 HTTP 클라이언트를 만들 때 포트를 지정. 나는 HTTP와 같은 서버 시작했기 때문에 나를 위해

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

또는

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

그것은이었다 (TCP를 : //) 서버 대신 HTTPS (SSL : //).

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

대신 :

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