REST要求不能带$ C $光盘GET(URL太长) [英] REST request cannot be encoded for GET (URL too long)

查看:170
本文介绍了REST要求不能带$ C $光盘GET(URL太长)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:


  • 网址:<一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 the X-HTTP-Method-Override header to tell the Translate API to treat the request as a GET (use X-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆