Ruby Net :: HTTP无法解码gzip? [英] Ruby Net::HTTP not decoding gzip?
本文介绍了Ruby Net :: HTTP无法解码gzip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了localhost:80
是nginx简单测试页.
I have ruby-1.9.3-p327 with zlib installed. localhost:80
is the nginx simple test page.
require "net/http"
=> true
Net::HTTP::HAVE_ZLIB
=> true
res = Net::HTTP.start("localhost", "80") do |http|
req = Net::HTTP::Get.new "/"
req["accept-encoding"] = "gzip"
http.request req
end
=> #<Net::HTTPOK 200 OK readbody=true>
res.get_fields "content-encoding"
=> ["gzip"]
res.body
=> "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\xEC\xBDi..."
主体未解码.为什么?
推荐答案
如果您使用http.get
,它应该自动对其进行解码,但是看起来request
可能不会为您完成此操作.
If you use http.get
it should decode it automaticlly, but it looks like request
might not do it for you.
这里显然有用于解压缩gzip请求的代码,但仅用于get
方法:
https://github.com/ruby/ruby/blob /v1_9_3_327/lib/net/http.rb#L1031
There clearly is code to decompress the gzip request here, but only for the get
method:
https://github.com/ruby/ruby/blob/v1_9_3_327/lib/net/http.rb#L1031
这篇关于Ruby Net :: HTTP无法解码gzip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文