Latest web development tutorials

HTTP methods: GET POST Comparison

The two most common HTTP methods: GET and POST.


What is HTTP?

Hypertext Transfer Protocol (HTTP) is designed to ensure the communication between the client and the server.

HTTP is a request works between client and server - response protocol.

web browser may be the client, and network applications on the computer may also be used as the server.

Example: the client (browser) to submit an HTTP request to the server; the server returns the response to the client. The response contains status information about the request and the content may be requested.


Two kinds of HTTP request methods: GET and POST

Between the client and the server request - response to the two most commonly used methods are: GET and POST.

  • GET - request data from the specified resource.
  • POST - submission of data to be processed to the designated resources.

GET Method

Please note that the query string (name / value pairs) are sent in the URL GET request:

/test/demo_form.php?name1=value1&name2=value2

GET requests about some of the other comments:

  • GET request can be cached
  • GET request remains in the browser history
  • GET requests can be bookmarked
  • GET requests should not be used when dealing with sensitive data
  • GET requests have length restrictions
  • GET requests should only be used to retrieve data

POST method

Please note that the query string (name / value pairs) are sent in an HTTP POST request message body of:

POST /test/demo_form.php HTTP/1.1
Host: w3cschool.cc
name1=value1&name2=value2

POST requests about some of the other comments:

  • POST requests are not cached
  • POST requests are not retained in the browser history
  • POST can not be bookmarked
  • POST requests for data length does not require

Comparison GET and POST

The following table compares the two HTTP methods: GET and POST.

  GET POST
后退按钮/刷新 无害 数据会被重新提交(浏览器应该告知用户数据会被重新提交)。
书签 可收藏为书签 不可收藏为书签
缓存 能被缓存 不能缓存
编码类型 application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data。为二进制数据使用多重编码。
历史 参数保留在浏览器历史中。 参数不会保存在浏览器历史中。
对数据长度的限制 是的。当发送数据时,GET 方法向 URL 添加数据;URL 的长度是受限制的(URL 的最大长度是 2048 个字符)。 无限制。
对数据类型的限制 只允许 ASCII 字符。 没有限制。也允许二进制数据。
安全性 与 POST 相比,GET 的安全性较差,因为所发送的数据是 URL 的一部分。

在发送密码或其他敏感信息时绝不要使用 GET !
POST 比 GET 更安全,因为参数不会被保存在浏览器历史或 web 服务器日志中。
可见性 数据在 URL 中对所有人都是可见的。 数据不会显示在 URL 中。


Other HTTP request methods

The following table lists some of the other HTTP request methods:

方法 描述
HEAD 与 GET 相同,但只返回 HTTP 报头,不返回文档主体。
PUT 上传指定的 URI 表示。
DELETE 删除指定资源。
OPTIONS 返回服务器支持的 HTTP 方法。
CONNECT 把请求连接转换到透明的 TCP/IP 通道。