新手问题 怎么判断网站是 http 还是 https

eaonll · July 03, 2018 · Last by franklinyu replied at July 07, 2018 · 3738 hits

我这边拿到ip 和端口, 由于不知道网站是否为 http 还是 https。。。我不是很愿意请求 2 次,不知道大家有什么好的办法。 或者我判断端口是否 443,8443 等。但是我又觉得不是很科学。

你想判断服务器有没有开 80 或者 443 端口,当然是遍历……

Reply to FrankFang

不需要呀。我已经知道端口是开启的。我只是需要判断是否是 http,还是 https

把端口当成 SSL 端口尝试一下咯

require 'openssl'
s = TCPSocket.new 'baidu.com', 80
ss = OpenSSL::SSL::SSLSocket.new s, OpenSSL::SSL::SSLContext.new
ss.connect # 抛出 OpenSSL::SSL::SSLError
Reply to luikore

好的。多谢了

什麼坑爹網站在 443 開 HTTP 的…… 還是說,直接使用了非常規端口?

You need to Sign in before reply, if you don't have an account, please Sign up first.