如何将巨大的参数列表发送到GET请求 [英] How to send a huge parameter list to a GET request
问题描述
我的服务器中有一个REST API,其中 List 操作(应使用GET方法实现)从客户端接收多个参数:
I have a REST API in my server, where the List operation (that should be implemented using the GET method) receives multiple parameters from the client:
- 当前页面
- 行数
- 用于执行快速搜索的文本
- 为搜索定义复杂过滤器的对象(格式为字段op值"的规则集)
- The current page
- The number of rows
- A text for performing a quick search
- An object that defines a complex filter for the search (set of rules in the form 'field op value')
由于这个用于过滤搜索的复杂对象,我需要将List定义为POST,我认为这不是一个好主意,因为REST将list操作定义为GET.
Due to this complex object for filtering the search, I need to define the List as POST, what I think that it's not a good idea, as REST defines the list operation as GET.
我的问题很简单:有什么方法可以使用GET方法解决此问题,而避免使用带有参数的庞大URL调用它?
My question is simple: there exists any way to solve this using a GET method, avoiding to call it with an huge URL with parameters?
推荐答案
感谢您的回答.似乎这个问题确实令人担忧,因为尚无明确有效的答案.由开发人员决定如何处理它.
Thanks to your answers. It seems that this question is really concerning, because there is not a clear valid answer. It's up to the developer to decide how to deal with it.
- REST表示您应该使用GET方法进行列表,但是大型URI非常难看.如今有什么问题吗?似乎没有问题,因为大多数浏览器都支持非常大的URI(Internet Explorer,回家,您不玩此游戏)
- 您也可以使用PUT/POST方法进行列表,但似乎并不能满足REST原则
- 您可以使用GET方法来传递简单参数,并将复杂参数附加到主体中,但是它不能满足HTTP原理
因此,最好的方法似乎是第一种:使用GET并构建巨大的URI.
So it seems that the best approach is the first one: use GET and build huge URIs.
这篇关于如何将巨大的参数列表发送到GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!