Resolve Net::HTTPBadResponse: wrong status line

In Ruby/Rails, if you’re running into the following error:

Net::HTTPBadResponse: wrong status line

When attempting to post data to a secure (https) url, with something similar to:


Then you can rewrite your request to avoid the exception like this:

url = URI.parse("")
http =,url.port)
http.use_ssl = true
request =,{})
request = http.request(request)

After which, you can access the request response in the same way as always.

Leave a Reply

Your email address will not be published. Required fields are marked *