Rails-Api limits length of url

时间:2016-04-25 08:54:42

标签: ruby-on-rails ruby url url-encoding

When sending a request to my rails app:

http://0.0.0.0:3334/v1/api/notebooks/users/verified/courses/None/files/asset-v1%3AedX%2BDemoX%2BDemo_Course%2Btype%40asset%2Bblock%40Welcome_R__-_demo.ipynb

I notice that params that rails passes to the controller are:

Parameters: {"username"=>"verified", "course"=>"None", "file"=>"asset-v1:edX+DemoX+Demo_Course+type@asset+block@Welcome_R__-_demo"}

It has removed the period, or .fileextension. I realise this is because rails seems to have some set maximum length for a url. Is there a way to get around this?

2 个答案:

答案 0 :(得分:2)

The last part of a URL is usually pulled out as params[:format]. You can avoid this by specifying your path as /*path, but usually putting the format parameter back on is not a big deal.

答案 1 :(得分:1)

Extremely long URLs are usually a mistake. URLs over 2,000 characters will not work in the most popular web browser. Don't use them if you intend your site to work for the majority of Internet users.

When you wish to submit a form containing many fields, which would otherwise produce a very long URL, the standard solution is to use the POST method rather than the GET method:

<form action="myaction" method="POST">
   ...
</form>

Check more about limits here