我安装了带有zlib的ruby-1.9.3-p327版本。 localhost:80
是nginx的简易测试页面。
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..."
身体没有解码。为什么?