REST 请求无法为 GET 编码(URL 太长) [英] REST request cannot be encoded for GET (URL too long)
问题描述
例子:
方法:GET
响应:collection
中的所有项目都匹配 一个搜索词
.
Response: All items in collection
matching a search term
.
问题:搜索词可能太长,以至于超出了网络服务器的最大值网址长度.
Problem: The search term may be so long that it breaks the web server's maximum URL length.
我如何允许极长的搜索字词仍然保持 RESTful?
推荐答案
为了获得灵感,我刚刚查看了 Google 翻译的API v2,使用RESTful 调用风格."
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-Method-Override
标头告诉翻译 API 以将请求视为 GET
(使用 X-HTTP-Method-Override:获取
).
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-method-override 标记我的问题.)
(This discovery led me to add the x-http-method-override tag to my question.)
这篇关于REST 请求无法为 GET 编码(URL 太长)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!