我读到Net::HTTP在编码为gzip时自动解压文件...我下载了一个xml文件,但保存在我的文件夹中的文件仍然是一个.gz文件,有什么办法吗?
uri = URI(URI.encode(URL))
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new(uri.path, { "Accept-Encoding" => "gzip", "User-Agent" => "gzip" })
request.basic_auth AUTHENTICATION[:username], AUTHENTICATION[:password]
http.request request do |response|
open "./storage/file/index_full.xml.gz", 'wb' do |io|
response.read_body do |chunk|
puts "Writing #{chunk.length} bits ..."
io.write chunk
end
end
end
end