REST要求不能带$ C $光盘GET(URL太长) [英] REST request cannot be encoded for GET (URL too long)
问题描述
例如:
-
网址:<一href=\"http://example.com/collection/a%20search%20term\">http://example.com/collection/a%20search%20term
方法: GET
响应:在集
匹配搜索词
问题:搜索字词可能是这么长时间,它打破了Web服务器的最大
URL的长度。
Problem: The search term may be so long that it breaks the web server's maximum URL length.
的如何让极长的搜索条件,仍然留REST风格的?的
推荐答案
有关灵感,我只是看着谷歌翻译的API V2 ,它的使用
REST风格的调用风格。的
For inspiration, I just looked at Google Translate's API v2, which is "using the RESTful calling style."
自然地,文本翻译可能相当长。所以谷歌可选
允许发送带有 POST
,但与一捻一个请求:
Naturally, texts to be translated can be quite long. And so Google optionally
allows sending a request with POST
, but with a twist:
要使用 POST
,你必须使用 X-HTTP-方法,覆盖
头告诉
翻译API来处理请求作为 GET
(使用 X-HTTP-方法,改写:
)。
GET
To use
POST
, you must use theX-HTTP-Method-Override
header to tell the Translate API to treat the request as aGET
(useX-HTTP-Method-Override: GET
).
所以有可能的语义的变换 POST
请求转换成 GET
要求
So it is possible to semantically transform a POST
request into a GET
request.
(这一发现促使我加入的 X-HTTP的方法,重写标记我的问题。)
(This discovery led me to add the x-http-method-override tag to my question.)
这篇关于REST要求不能带$ C $光盘GET(URL太长)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!