Showing posts with label https. Show all posts
Showing posts with label https. Show all posts
Saturday, October 27, 2018
Net::HTTP error 400 (bad request) with HTTPS
Hello, friends!
Yesterday I got stuck when trying to connect to an HTTPS site using Net::HTTP:
http = Net::HTTP.new('server.com', 443)
response = http.send_request('GET', path, parameters, headers)
I was getting error 400 in response.code.
What is not well documented is that when accessing a server via HTTPS protocol it's not enough to set port to 443. You must also set use_ssl to true:
Yesterday I got stuck when trying to connect to an HTTPS site using Net::HTTP:
http = Net::HTTP.new('server.com', 443)
response = http.send_request('GET', path, parameters, headers)
I was getting error 400 in response.code.
What is not well documented is that when accessing a server via HTTPS protocol it's not enough to set port to 443. You must also set use_ssl to true:
http = Net::HTTP.new('server.com', 443)
http.use_ssl = true
response = http.send_request('GET', path, parameters, headers)
I found that by seeing code at http://www.rubyinside.com/nethttp-cheat-sheet-2940.html.
http.use_ssl = true
response = http.send_request('GET', path, parameters, headers)
I found that by seeing code at http://www.rubyinside.com/nethttp-cheat-sheet-2940.html.
Subscribe to:
Posts (Atom)
