Reputation: 25
I want to convert http
to https
URL in Ruby.
Let me explain how my method works:
http:devalphaserver.com/xxx/12
.to https
(https:devalphaserver.com/xxx/12
) in Ruby to do the Get Operation. The issue which I'm facing now is when I try to do get operation using http
, I'm getting 302 Found stating that The document has moved https:devalphaserver.com/xxx/12
here.
Please help. Thanks!
Upvotes: 1
Views: 2356
Reputation: 42453
url = "http:devalphaserver.com/xxx/12"
http_uri = URI(url)
https_uri = URI(http_uri.tap { |u| u.scheme = 'https' }.to_s)
Upvotes: 0
Reputation: 16506
Convert http to https using Ruby
url = "http:devalphaserver.com/xxx/12"
uri = URI.parse(url)
uri.scheme = "https"
uri.to_s
# => "https:devalphaserver.com/xxx/12"
However going through your question, I can see its a case of 302 redirect. If you are using gems like REST Client or HTTParty they have in place the mechanism of result handling that takes care of url redirect automatically.
Upvotes: 10