I'm having a bit of trouble understudying why Rails 3.2.6 is parsing a multipart POST request that contains json.
在研究Rails 3.2.6解析包含json的多部分POST请求时,我遇到了一点麻烦。
The 'offending' curl command:
“冒犯”curl命令:
curl -i -X POST --silent http://localhost:3000/foo.json --form foo='{"name":"bar"};type=application/json'
Rails interprets as:
Rails解释为:
p params[:foo] #=> "{\"name\":\"bar\"}"
Note how the value is a string, not a hash (of parsed JSON).
注意该值是一个字符串,而不是一个散列(解析JSON)。
The headers sent by curl seem correct:
curl发送的头部看起来是正确的:
> POST /foo.json HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:3000
> Accept: */*
> Content-Length: 208
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------959d0620faa3
The multipart's type also seems to be correct:
多重部分的类型似乎也是正确的:
------------------------------959d0620faa3
Content-Disposition: form-data; name="foo"
Content-Type: application/json
{"name":"bar"}
------------------------------959d0620faa3--
Could someone help me understand the best way to get to a place where params[:foo] returns the parsed json hash, as opposed to its string representation?
有人能帮我理解到解析json散列(而不是它的字符串表示)的最佳方式吗?
Thank you.
谢谢你!
1 个解决方案
#1
1
Rails doesn't parse json parameters by default, you'll have to do it manually.
Rails默认不解析json参数,您必须手动解析。
#1
1
Rails doesn't parse json parameters by default, you'll have to do it manually.
Rails默认不解析json参数,您必须手动解析。