Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTTP Methods: GET vs POST

HTTP Methods: GET vs POST


The two most commonly used HTTP methods are GET and POST.


What is HTTP?

HyperText Transfer Protocol (HTTP) is designed to ensure communication between a client and a server.

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

A web browser may be the client, while a web application on a computer may act as the server.

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


Two HTTP Request Methods: GET and POST

When making a request-response between a client and a server, the two most commonly used methods are GET and POST.

GET parameters are usually shown in the URL, while POST submits data through a form and does not show it in the URL, making POST more private:


GET Method

Note that the query string (name/value pairs) is sent in the URL of a GET request:

/test/demo_form.php

?name1=value1&name2=value2

Some other notes about GET requests:


POST Method

Note that the query string (name/value pairs) is sent in the HTTP message body of a POST request:

POST /test/demo_form.php HTTP/1.1

Host: runoob.com

name1=value1&name2=value2

Some other notes about POST requests:


Comparing GET and POST

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

  GET POST
Back button / Reload Harmless Data will be resubmitted (the browser should inform the user that the data will be resubmitted).
Bookmark Can be bookmarked Cannot be bookmarked
Caching Can be cached Cannot be cached
Encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data.
History Parameters are retained in browser history. Parameters are not saved in browser history.
Restrictions on data length Yes. When sending data, the GET method adds data to the URL; the length of a URL is limited (the maximum URL length is 2048 characters). No restrictions.
Restrictions on data types Only ASCII characters are allowed. No restrictions. Binary data is also allowed.
Safety GET is less secure than POST because the data sent is part of the URL.
 在发送密码或其他敏感信息时绝不要使用 GET ! | POST 比 GET 更安全,因为参数不会被保存在浏览器历史或 web 服务器日志in. |

| Visibility | The data is visible to everyone in the URL. | The data is not displayed in the URL. |


Other HTTP Request Methods

The table below lists some other HTTP request methods:

Method Description
HEAD Same as GET, but returns only the HTTP headers, not the document body.
PUT Upload the representation of the specified URI.
DELETE Delete the specified resource.
OPTIONS Return the HTTP methods supported by the server.
CONNECT Convert the request connection to a transparent TCP/IP tunnel.