Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

GET / POST 区别

21 Mars 2015 Publié dans #webservice

在rest service中, 有get、post两种请求模式。有时候可以达到同样的效果。但是背后却有区别。

1. 表达:



GET /blog/?name1=value1&name2=value2 HTTP/1.1
Host: XXXX.com


POST /blog/ HTTP/1.1
Host: XXXX.com
name1=value1&name2=value2

2. GET的好处

  1. GET requests can be cached
  2. GET requests can remain in the browser history
  3. GET requests can be bookmarked
  4. GET requests can be distributed & shared
  5. GET requests can be hacked (ask Jakob!)

3.POST 使用时候应处理敏感字符 如用户名密码之类的

4.POST处理长请求

5.GET 和AJAX 环境结合

因为XMLHttpRequest中,浏览器处理POST有两步操作,先发header,再发payload。这样的话GET会更快一些。

另外可以参考:http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

Publicité
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article