恩codeuricomponent在轨对其进行解码对其、codeuricomponent

2023-09-10 19:20:27 作者:你是一朵奇葩*

通常情况下轨神奇地去codeS均 PARAMS 。现在,我得到一个JavaScript这确实 PARAMS =值=+ EN codeURIComponent('AB#CD'); ,然后调用 HTTP ://服务器/控制器值= AB%23cd ?。如果我访问 PARAMS [:值] 在我的控制器,它包含 AB%23cd ,而不是 AB#CD 因为我期望的那样。

Normally rails magically decodes all params. Now I got a javascript which does params="value="+encodeURIComponent('ab#cd'); and then calls http://server/controller?value=ab%23cd. If I access params[:value] in my controller, it contains ab%23cd and not ab#cd as I would expect.

如何解决此问题?为什么导轨这个参数没有自动解码?

How to solve this? Why does rails no auto decoding of this param?

推荐答案

Rails的自动的处理参数与以下逻辑。

Rails "automagically" handles parameters with the following logic.

如果请求的是得到它会去查询字符串code什么:

If the request is GET it will decode anything in the query string:

GET http://server/controller?value=ab%23cd
  On the server this will generate params['value'] as ab#cd

如果该请求是一个查询字符串POST它将C中,它不会去$ C $:

If the request is a POST with a query string it will not decode it:

POST http://server/controller?value=ab%23cd
  On the server this will generate params['value'] as ab%23cd

如果该请求是数据参数的POST,它会去code的:

If the request is a POST with data parameters, it will decode it:

POST http://server/controller
  data: value=ab%23cd
  On the server this will generate params['value'] as ab#cd

我怀疑你所看到的,因为你包括与 POST 的要求,而不是一个查询字符串,这个问题 GET 要求等Rails是不是查询字符串解码。

I suspect that you're seeing this issue because you're including a query string with a POST request instead of a GET request and so Rails isn't decoding the query string.

 
精彩推荐
图片推荐