ruby on rails - How do I set use_ssl param when running a web request through a proxy? -


i’m using rails 4.2.7. how set “use_ssl” parameter when sending web request through proxy? have this

    res1 = net::http.socksproxy(tcpsocket::socks_server, tcpsocket::socks_port).start(uri.host, uri.port) |http|       http.use_ssl = (uri.scheme == "https")       resp = http.get(uri, initheader = headers)       status = resp.code.to_i       if status == 302 || status == 301         redirect = resp['location']       end       content = resp.body       content_type = resp['content-type']       content_encoding = resp['content-encoding']     end 

but when line — “http.use_ssl = (uri.scheme == "https”)” exception

ioerror: use_ssl value changed, session started     /users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:758:in `use_ssl='     /users/davea/documents/workspace/myproject/app/helpers/webpage_helper.rb:96:in `block in get_content'     /users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:853:in `start'     /users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:584:in `start'     /users/davea/documents/workspace/myproject/app/helpers/webpage_helper.rb:94:in `get_content'     /users/davea/documents/workspace/myproject/app/helpers/webpage_helper.rb:33:in `get_url'     (irb):1     /users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/console.rb:110:in `start'     /users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/console.rb:9:in `start'     /users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:68:in `console'     /users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'     /users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>'     bin/rails:4:in `require'     bin/rails:4:in `<main>' 

according test sample, line 109: https://github.com/astro/socksify-ruby/blob/master/test/tc_socksify.rb#l109

i'd try this:

res1 = net::http.socksproxy(tcpsocket::socks_server, tcpsocket::socks_port).start(   uri.host, uri.port, :use_ssl => (uri.scheme == "https")) |http|    resp = http.get(uri, initheader = headers)   status = resp.code.to_i   if status == 302 || status == 301     redirect = resp['location']   end   content = resp.body   content_type = resp['content-type']   content_encoding = resp['content-encoding'] end 

if don't have valid ssl cert, can disable ssl validation (not recommended production!)

https://github.com/astro/socksify-ruby/blob/master/test/tc_socksify.rb#l110


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -