使用Ruby打开启用SSL的页面

时间:2017-11-17 08:50:16

标签: ruby

我想使用这个Ruby代码打开SSL网页:

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

但我得到错误:

<!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>

如何使代码与HTTPS和HTTP页面一起使用?

0 个答案:

没有答案