Ruby SSL_read: tlsv1 alert protocol version
<p>I'm writing a simple ssl web client which worked fine without adding ssl support. Now that I have added ssl functionality to get request I get this error message:</p>

<blockquote>
  <p>SSL_read: tlsv1 alert protocol version</p>
</blockquote>

<p>After googling about it, I came to conclusion to check openssl version, which I can see that it supports TLSv1.2. I even created a context to explicitly forcing tlsv1.2 but still same error message. My openssl version:</p>

<pre><code>ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION' ===&gt; OpenSSL 1.0.1f 6 Jan 2014
</code></pre>

<p>My code:</p>

<pre><code>    require 'socket'
    require 'openssl'

    puts "Please select:"
    puts "get ==&gt; to use GET method"
    puts "post ==&gt; to use POST method"
    method = gets.chomp.downcase

    case method
    when "get"
      print "Please enter the domain name to get the http: "
      domain = "www." &lt;&lt; gets.chomp
      print "Now enter the page you want to get: "
      page = gets.chomp

      # opening socket
      soc = TCPSocket.new domain, 443
      ctx = OpenSSL::SSL::SSLContext.new
      ctx.ssl_version = :TLSv1_2
      ssl = OpenSSL::SSL::SSLSocket.new(soc, ctx)
      ssl.sync_close = true
      ssl.connect
      soc.puts "GET #{page} HTTP/1.1\nHost: #{domain}\n\n\n"
      while line = ssl.gets
        puts line
      end
    when "post"
      print "Please enter the domain name to post the http:"
      domain = gets.chomp.downcase
      print "Now enter the post form page:"
      form_page = gets.chomp.downcase
      puts "Please enter the parameters of POST and related values one at a time:"
      puts "(\"done\" to end input)"
      post_variable = []
      while true
        print "Parameter:"
        parameter = gets.chomp.downcase
        break if parameter == "done"
        print "Value:"
        value = gets.chomp.downcase
        break if  value == "done"
        post_variable.push("#{parameter}=#{value}")
        post_sentense = post_variable.join("&amp;")
      end
      # opening socket
      soc = TCPSocket.new domain, 80
      soc.puts "POST #{form_page} HTTP/1.1\nHost: #{domain}\nContent-Length: #{post_sentense.length}\n\n\n#{post_variable}"
      while line = soc.gets
        puts line
      end
    else
      puts "wrong input!!!"
    end
</code></pre>

<p>I should mention that the domain name should be entered without www and page normally is <code>/index.html</code>.
Can someone help me through this???</p>