When sending an HTTParty.get()
request to a URL that redirects to another (one, or possibly more) URL(s), I get this error:
Zlib::DataError:
invalid code lengths set
# ./file/file_name.rb:63:in `block (3 levels) in <top (required)>'
How do I get around this, and why is it happening?
Set the Accept-Encoding
param in the headers option to blank:
resp = HTTParty.get(article.old_url, :verify => false, :headers => {'Accept-Encoding' => ''})
HTTParty was having errors decompressing the response (specifically gzip in my case), possibly because something strange was happening with the received Content-Type
header as a result of the redirect(s). Setting the Accept-Encoding header to blank returned something that HTTParty knew how to parse.