繁体   English   中英

在Ruby中使用Net :: HTTP.new时获取301重定向

[英]Getting 301 redirect when using Net::HTTP.new in Ruby

我正在Ruby中测试Net :: HTTP与proxy的结合使用,发现即使我在url中正确输入地址,我仍会通过代码获得301重定向。 使用相同的URI对象,如果我使用get_response(),则代码可以工作,但是如果使用以下方法,则代码将不工作。 不知道那里出了什么问题? 谢谢!

编辑:这似乎不是301关注的问题。 似乎与https有关,但不确定如何导航。

proxy_addr = nil
proxy_port = nil


url = URI("https://www.bloomberg.com/asia")

Net::HTTP.new('www.bloomberg.com', nil, proxy_addr, proxy_port).start { |http|
  res = http.get(url)
  puts res.code
  puts res.message
  puts res.header['location']

}

您需要在某处指定use_ssl

require 'net/http'
proxy_addr = nil
proxy_port = nil

http = Net::HTTP.new('www.bloomberg.com', 443, proxy_addr, proxy_port)
http.use_ssl = true
http.start
res = http.get('/asia')
puts res.code
puts res.message
puts res.header['location']

它通过http连接,服务器发送301重定向到https

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM