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:

Net::HTTP::post_form("https://www.example.com",{})

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

url = URI.parse("https://www.example.com")
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path,{})
request = http.request(request)

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

ABOUT THE AUTHOR

Anthony Leon

Author has no description.

NO COMMENTS

Leave a comment

Your email is never published or shared.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>