fix https cert error

This commit is contained in:
邱博亞 2021-01-11 20:29:49 +08:00
parent 19807613c2
commit 782e282058
1 changed files with 15 additions and 5 deletions

View File

@ -49,19 +49,29 @@ class SiteFeed
anns
end
def get_response_body(uri)
res = Net::HTTP.get_response(uri)
res = Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https',
open_timeout: 60,read_timeout: 60,
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
req = Net::HTTP::Get.new(uri)
http.request(req)
end
if res.code == "302" || res.code == "301"
location = res['Location']
cookie = res['Set-Cookie']
headers = {
'Cookie' => cookie,
}
if location[0] == "/"
uri = URI.parse("#{uri.scheme}://#{uri.host}#{location}")
else
uri = URI.parse(location)
end
res = Net::HTTP.get_response(uri,nil,headers)
res = Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https',
open_timeout: 60,read_timeout: 60,
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
req = Net::HTTP::Get.new(uri)
req['Cookie'] = cookie
http.request(req)
end
return res.body
else
return res.body