1

I want to use this Ruby code to open SSL web page:

redirect_url = response.parse_response['redirect_url']
  url = URI.parse(redirect_url)
  req = Net::HTTP::Get.new(url.to_s)
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.request(req)
  }
  puts res.body

But I get error:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
 Instead use the HTTPS scheme to access this URL, please.<br />
</p>
</body></html>

How I can make the code to work with HTTPS and HTTP pages?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • 2
    Possible duplicate of [Using Net::HTTP.get for an https url](https://stackoverflow.com/questions/5786779/using-nethttp-get-for-an-https-url) – Tom Lord Nov 17 '17 at 09:11

0 Answers0