2013-04-05 13 views
5

एसएसएल के माध्यम से इम्गुर एपीआई से कनेक्ट करने का प्रयास करने से मुझे एक त्रुटि मिलती है।HTTP पोस्ट पर अज्ञात त्रुटि (अज्ञात प्रोटोकॉल)

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 = Net::HTTP.new(API_URI.host, API_URI.port) 

या

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

मेरे लिए यह था, क्योंकि मैं एक http के रूप में सर्वर शुरू कर दिया था (टीसीपी: //) 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' 
संबंधित मुद्दे