I used RVM to install Ruby 2.0 on my Mac OS X Mountain Lion. OpenSSL is installed automatically by RVM before installing Ruby 2.0 (autolibs via Homebrew). My problem is that 'net/http' cannot request through HTTPS.
Here is my script:
require 'net/http'
uri = URI('https://github.com')
Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new uri
response = http.request request # Net::HTTPResponse object
end
puts response
Here is the output by running it:
/Users/siegfried/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:891:in `connect': undefined method `set_params' for #<OpenSSL::SSL::SSLContext:0x007ff1ad0acea8> (NoMethodError)
from /Users/siegfried/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /Users/siegfried/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /Users/siegfried/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:582:in `start'
from Desktop/test.rb:5:in `<main>'
Does anyone have a clue? Thanks.
Zhi-Qiang Lei
zhiqiang.lei@gmail.com
equire 'net/http'
uri = URI('https://github.com')
Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new uri
response = http.request request # Net::HTTPResponse object
end
puts response
Looks like it may be a precedence problem. Try changing to this:
Net::HTTP.start(uri.host, uri.port,
:use_ssl => (uri.scheme == 'https')) do |http|
It's binding the :use_ssl => uri.scheme first, then doing the compare…
···
On Oct 10, 2013, at 6:14 AM, Zhi-Qiang Lei <zhiqiang.lei@gmail.com> wrote:
I had the same problem, and I found just adding `require 'openssl'` at the
top of the script fixed the issue. I don't know why though, didn't have
this problem until updating to the latest ruby 2.0 via RVM.
···
On 11 October 2013 05:18, Tamara Temple <tamouse.lists@gmail.com> wrote:
On Oct 10, 2013, at 6:14 AM, Zhi-Qiang Lei <zhiqiang.lei@gmail.com> wrote:
> equire 'net/http'
>
> uri = URI('https://github.com')
>
> Net::HTTP.start(uri.host, uri.port,
> :use_ssl => uri.scheme == 'https') do |http|
> request = Net::HTTP::Get.new uri
>
> response = http.request request # Net::HTTPResponse object
> end
>
> puts response
Looks like it may be a precedence problem. Try changing to this:
> Net::HTTP.start(uri.host, uri.port,
:use_ssl => (uri.scheme == 'https')) do |http|
It's binding the :use_ssl => uri.scheme first, then doing the compare…
Here is an example:
http = Net::HTTP.start('github.com', 443, :use_ssl => true)
NoMethodError: undefined method `set_params' for
#<OpenSSL::SSL::SSLContext:0x007f9249170d80>
from
/Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:891:in
`connect'
from
/Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in
`do_start'
from
/Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:857:in
`start'
from
/Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:582:in
`start'
from (irb):5
from /Users/samuel/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0p247 :006 > require 'openssl'
=> true
2.0.0p247 :007 > http = Net::HTTP.start('github.com', 443, :use_ssl => true)
=> #<Net::HTTP github.com:443 open=true>
···
On 4 November 2013 17:19, Samuel Williams <space.ship.traveller@gmail.com>wrote:
I had the same problem, and I found just adding `require 'openssl'` at the
top of the script fixed the issue. I don't know why though, didn't have
this problem until updating to the latest ruby 2.0 via RVM.
On 11 October 2013 05:18, Tamara Temple <tamouse.lists@gmail.com> wrote:
On Oct 10, 2013, at 6:14 AM, Zhi-Qiang Lei <zhiqiang.lei@gmail.com> >> wrote:
> equire 'net/http'
>
> uri = URI('https://github.com')
>
> Net::HTTP.start(uri.host, uri.port,
> :use_ssl => uri.scheme == 'https') do |http|
> request = Net::HTTP::Get.new uri
>
> response = http.request request # Net::HTTPResponse object
> end
>
> puts response
Looks like it may be a precedence problem. Try changing to this:
> Net::HTTP.start(uri.host, uri.port,
:use_ssl => (uri.scheme == 'https')) do |http|
It's binding the :use_ssl => uri.scheme first, then doing the compare…
I fixed the problem by reinstalling ruby by RVM.
Zhi-Qiang Lei
zhiqiang.lei@gmail.com
···
On Nov 4, 2013, at 12:23 PM, Samuel Williams <space.ship.traveller@gmail.com> wrote:
Here is an example:
http = Net::HTTP.start('github.com', 443, :use_ssl => true)
NoMethodError: undefined method `set_params' for #<OpenSSL::SSL::SSLContext:0x007f9249170d80>
from /Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:891:in `connect'
from /Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:857:in `start'
from /Users/samuel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:582:in `start'
from (irb):5
from /Users/samuel/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
2.0.0p247 :006 > require 'openssl'
=> true
2.0.0p247 :007 > http = Net::HTTP.start('github.com', 443, :use_ssl => true)
=> #<Net::HTTP github.com:443 open=true>
On 4 November 2013 17:19, Samuel Williams <space.ship.traveller@gmail.com> wrote:
I had the same problem, and I found just adding `require 'openssl'` at the top of the script fixed the issue. I don't know why though, didn't have this problem until updating to the latest ruby 2.0 via RVM.
On 11 October 2013 05:18, Tamara Temple <tamouse.lists@gmail.com> wrote:
On Oct 10, 2013, at 6:14 AM, Zhi-Qiang Lei <zhiqiang.lei@gmail.com> wrote:
> equire 'net/http'
>
> uri = URI('https://github.com')
>
> Net::HTTP.start(uri.host, uri.port,
> :use_ssl => uri.scheme == 'https') do |http|
> request = Net::HTTP::Get.new uri
>
> response = http.request request # Net::HTTPResponse object
> end
>
> puts response
Looks like it may be a precedence problem. Try changing to this:
> Net::HTTP.start(uri.host, uri.port,
:use_ssl => (uri.scheme == 'https')) do |http|
It's binding the :use_ssl => uri.scheme first, then doing the compare…