Rails:如何解压缩压缩的 xml 请求正文? [英] Rails: how to unzip a compressed xml request body?

查看:37
本文介绍了Rails:如何解压缩压缩的 xml 请求正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 rails 3 站点,它从 iPhone 应用程序获取 xml 请求(包括文件提交).iphone 应用程序压缩其 xml 请求的主体,这些请求像这样传递到我的控制器(这是一个简单的请求,只更新几个细节而不是发送任何文件):

I have a rails 3 site which gets xml requests (incluing file submissions) from an iphone app. The iphone app compresses the body of its xml requests, which come through to my controller like this (this is a simple one that just updates a couple of details rather than sends any files):

params = {"\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x035\xCAA\x0E\x83 \x10@\xD1\xD3\xE8\xD20\x02R\x17\xDD4\xBD\x87\x01\x9CZ\"H\x03CHo\xDF\xB2`\xFB\xDFO\xF8\x89\x89\x06\xF9\xA81\x9D/\x1F\xEB\x96IS\xC9\x83|\xDE\xF9\x98\xBA\xE2E\xE9\xBB\xD9X.j\xC2F"=>{"\xE8\xFD\xEF\xE4\x02\xB6\x00\x1C\x18\x13\x1C\xA4\xEC\x82A"=>nil}, "\xDF\x88\xA2\xCEt\xBA}\xAA\xCE{\xA7C\x1E\x04"=>nil, "\x1AN6\x86~gw\xB4\xD7\x00\x82\xE0r\xC1\x9D\x8B\xDB\xAC\xD6uF.\xCCb%\x03\x83\xA0\xD4\x0F~\xA0o\x1F\xAE\x00\x00"=>nil, "action"=>"update", "controller"=>"reports", "id"=>"65", "format"=>"xml"}

它应该看起来像这样:

params = {"report"=>{"workflow_status"=>"-1", "entry_count"=>"0"}, "auth"=>{"time"=>"1310044269", "email"=>"fake@fakedomainzzz.com", "sig"=>"686062dbc27ef49baa69be77a0ba6362"}, "action"=>"update", "controller"=>"reports", "id"=>"65", "format"=>"xml"}

请注意,第一个示例不是第二个示例的压缩版本,即某些值会有所不同,但整体结构应该相同(解压缩后).

Note that the first example is NOT a compressed version of the second, ie some of the values will be different, but the overall structure should be the same (once it's unzipped).

谁能告诉我如何解压?压缩后的参数来自请求正文,在某些情况下还包括文件数据.

Can anyone tell me how i unzip it? The zipped params come from the request body, which will also include filedata in some cases.

感谢任何建议 - 最大

grateful for any advice - max

推荐答案

您可以使用 Richard Schneeman 的回答:

Mime::Type.register "gzip/json", :gzipjson
config.middleware.delete "ActionDispatch::ParamsParser"
config.middleware.use ActionDispatch::ParamsParser , { Mime::GZIPJSON => Proc.new { |raw_request | data = ActiveSupport::JSON.decode(ActiveSupport::Gzip.decompress(raw_request)); data = {:_json => data} unless data.is_a?(Hash); data.with_indifferent_access }}

这应该在 config/environment.rb

这篇关于Rails:如何解压缩压缩的 xml 请求正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆