在处理传入数据时,是否有真正的理由来区分 POST 和 GET? [英] Is there any real reason to differentiate between POST and GET when handling incoming data?

查看:19
本文介绍了在处理传入数据时,是否有真正的理由来区分 POST 和 GET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在使用一个包装 PHP 类来获取 GET 和 POST 数据,并让我使用单个 getter 函数访问它.在开发 Web 应用程序多年之后,我从来没有一个很好的理由去关心传入的 var 是来自 POST 还是 GET.不仅如此,我真的厌倦了必须检查两个数组中的单个变量.

Lately I've been using a wrapper PHP class that fetches GET and POST data and lets me access it using a single getter function. After years of developing web applications I've never had a single good reason to care whether an incoming var was coming from POST or GET. Not only that but I got really sick and tired of having to check both arrays for a single variable.

今天我注意到codeigniter有一个用于POST数据的getter函数和一个用于GET的getter函数.这有什么道理吗?这里有人有理由关心他的数据来自哪里吗?

Today I noticed that codeigniter has one getter function for POST data and one for GET. Is there any point to this? Has anyone here ever had a reason to care where his data is coming from?

一些说明:我不是在问 POST 或 GET 之间的区别,也不是我应该使用哪个将数据发送到页面.我在问我是否应该关心数据是通过 GET 还是 POST 到达我的页面.

A couple of clarifications: I'm not asking about the differences between POST or GET or which one I should use to send data to a page. I'm asking about whether I should care if data is arriving to my page via GET or POST.

推荐答案

HTTP 标准为 get/post 操作定义了不同的语义(http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html Sec 9.1.1)

The HTTP standard defines different semantics for get/post operations (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html Sec 9.1.1)

特别是您可以使用来自 get 请求的数据进行信息检索,但您不应该做任何涉及状态更改概念的事情.一个原因是用户代理可能会在用户实际上没有点击链接的情况下预取页面(并执行获取请求).(同意这在网络浏览器中并不常见,但我听说过邮件客户端这样做)

In particular you can do information retrieval using data coming from a get request, but you shouldn't do anything which involves some notion of state change. One reason for this is that the user agent may prefetch pages (and doing get requests) without the user actually having clicked on a link. (Agreed that is notvery common among web browsers, but i've heard of mail clients doing that)

这篇关于在处理传入数据时,是否有真正的理由来区分 POST 和 GET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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