GET 和 POST 哪个更紧凑?

发布于 2024-08-06 18:38:00 字数 48 浏览 4 评论 0原文

由于 GET 请求必须进行 URL 编码,因此 POST 是否比 GET 更紧凑?

Is POST more compact than GET, since GET requests have to be URL-encoded?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

涙—继续流 2024-08-13 18:38:00

两者有完全不同的目的,所以我不会以这种方式比较它们。 GET 用于数据检索,除此之外应该没有副作用。 POST 用于发送数据,而不是检索数据。

Both have completely different purposes, so I wouldn't compare them in that way. GET is for data retrieval, and should have no side effects beside that. And POST is for sending data, not retrieving them.

安静被遗忘 2024-08-13 18:38:00

邮政也是如此。它们同样紧凑。这是数据去向的问题。对于 POST,它进入请求正文。对于 GET — 进入 URL 本身。此外,如果使用 multpart/form-data 编码(这是文件上传所必需的,但在这种情况下 GET 请求无论如何都不是一个选项),POST 会更加冗长。

So are POST. They're equally compact. It's a matter of where the data go. For POST it goes into request body. For GET — into URL itself. Moreover, in case of multpart/form-data encoding (which is required for file uploads, but in this case GET request is not an option, anyway) POST will be more verbose.

半暖夏伤 2024-08-13 18:38:00

不,POST 请求仍然必须放入 http 查询中。您只是看不到它们作为 URL 的一部分。

IE 这是 get 查询

  GET <url with params>

与 post 查询

  POST <url>
  ...
  <params>

No, POST requests still have to be put into the http query. You just don't see them as part of the URL.

IE here's a get query

  GET <url with params>

vs a post query

  POST <url>
  ...
  <params>
寂寞陪衬 2024-08-13 18:38:00

POST 比 GET 多一个字母,因此不够紧凑。

如果紧凑性非常重要并且您不关心 HTTP 语义,请改用二进制协议。 POST 和 GET 的语义不同,并且 HTTP 没有针对紧凑性进行优化。

POST has one more letter in it than GET, so it's less compact.

If compactness is very important and you don't care about HTTP semantics, use a binary protocol instead. The semantics of POST and GET are different, and HTTP is not optimised for compactness.

夕色琉璃 2024-08-13 18:38:00

您可能需要查看以下有关 get 与 post 可用性的信息。
http://www.w3.org/2001/tag/doc/whenToUseGet。 html

总结一下:

使用 GET if:

交互更像是一个问题。例如,查找、只读操作等。

在以下情况下使用 POST:

交互更像是订单,更改资源的状态,或者用户将对交互结果负责。

请注意,这些都没有考虑请求的大小。为了更多地思考,您可能会考虑互联网的早期,当时搜索引擎仅通过对它们抓取的链接执行 GET 请求而导致数据库问题。这是因为一些程序员使用 GET 请求来更改资源的状态(例如删除记录、删除表等)。

You might want to review the following information regarding get vs post usability.
http://www.w3.org/2001/tag/doc/whenToUseGet.html

To sum it up:

use GET if:

The interaction is more like a question. For example, lookups, read only operations, etc.

use POST if:

The interaction is more like an order, changes the state of a resource, or the user will be held accountable for the results of the interaction.

Note that none of this takes into account the SIZE of the request. For more thought, you might consider the early days of the internet when search engines caused database problems simply by performing GET requests on the links they crawled. This was because some programmers used GET requests to change the state of resources (such as deleting records, dropping tables, etc).

我是有多爱你 2024-08-13 18:38:00

简单说明一下:根据 Yahoo YUI 团队和 YSlow 的说法,当使用 XMLHttpRequest 对象(AJAX)时,POST 几乎总是使用两个数据包,而 GET 将使用一个数据包(内容长度允许)。

这意味着如果您使用 GET,您的 AJAX 请求将“更加紧凑”。

来源:

http://developer.yahoo.com/performance/rules.html#ajax_get< /a>

Just a quick note: According to Yahoo YUI team and YSlow, when using XMLHttpRequest objects (AJAX), POST almost always uses two packets, while GET will use one (content length permitting).

This means that your AJAX requests are "more compact" if you use GET.

Source:

http://developer.yahoo.com/performance/rules.html#ajax_get

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文