巴别塔上的雇工


GET vs POST: Don’t Mis-Use It Now
4月 12, 2008, 6:24 上午
Filed under: 技术体会
HTTP常用的两个命令是GET和POST,从表面上看区别,GET命令是没有content的,如果需要传递参数给服务器端,需要把参数放在URI中;POST命令是可以有content的,这样可以在content里面放置传递给server端的信息,如果参数非常大,放在URI里面就不合适了,只能用POST。但是,不应该根据参数大小来决定用GET和POST,而是应该根据这个操作是要获取信息还是修改信息来决定。

HTML中的form可以选择用GET或者POST方法发送给服务器端,HTML的Specification的描述是:

If the processing of a form is idempotent (i.e. it has
no lasting observable effect on the state of the world),
then the form method should be
GET.
Many database searches have no visible side-effects and make ideal applications of query forms.

If
the service associated with the processing of a form has side effects
(for example, modification of a database or subscription to a service),
the method should be POST.

对于idempotent/idempotence的定义,RFC2616地描述是


Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of
N > 0 identical requests is the same as for a single request.

这要在以前,就算在网站中用错了GET和POST,也没什么大问题,但是今天看到Google的Crawler开始处理form了,这样一来,如果把该用POST的用成GET可就坏了。对于要扒整个internet的Crawler来说,一般都会避免跟进FORM连接,因为Crawler作为程序也不知道该往FORM里面填写什么,不过显然Google觉得自己的处理能力绰绰有余,而且目前扒Internet深度还不够,所以选择跟进GET Form,但是不处理POST Form。如果哪个网站误把可能改变服务器状态的FORM标为用GET方法的话,就会被Google Crawler骚扰一把。


发表评论 so far
留下评论



留下评论