Home >>HTTP Tutorial >HTTP Methods
The set of common methods for HTTP/1.1 are listed below. Based on the requirements this collection can be extended. These methods are called case sensitive, and must be used in uppercase.
Sr No | Method and Description |
---|---|
1. | GET Using a given URI, the GET method is used to remember information from the given server. Applications using GET can only retrieve data and have no further impact on the data. |
2. | HEAD Same as GET but just moves the section of the status line and the header. |
3. | POST Using HTML types, for example, a POST request is used to send data to the server, customer information, file upload etc. |
4. | PUT Replaces the content uploaded with all current representations of the target resource. |
5. | DELETE Removes all current object resource representations provided by a URI. |
6. | CONNECT Sets up a tunnel identified by a given URI to the server. |
7. | OPTIONS Describes aim resource communication choices. |
8. | TRACE Needs to carry out a message loop-back test along the way to the target resource. |
A GET request recovers data from a Web server by defining parameters in the request's URL portion. This is the primary tool used to obtain records. The following example to get hello.htm makes use of the GET method:
GET /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.phptpoint.com Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive
The server response against the above GET request will be as follows:
HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32) Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed
<html> <body> <h1>Hello, World!</h1> </body> </html>
The HEAD approach is functionally similar to GET, except that a response line and headers are replied by the server, but no entity-body. The following example uses the HEAD method to collect hello.htm header information:
HEAD /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.phptpoint.com Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive
The server response to the GET request above will be as follows:
HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32) Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed
You will note that no data is sent after header by the server here.
The POST method is used when you want to send any data, such as file changes, form data, etc. to the server. The following example uses the POST method to send the data of a form to the server, which is processed by a process.cgi and finally a response is returned:
POST /cgi-bin/process.cgi HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.phptpoint.com Content-Type: text/xml; charset=utf-8 Content-Length: 88 Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?> <string xmlns="http://clearforest.com/">string</string>
The process.cgi server side script processes the passed data and sends out the following reply:
HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32) Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed
<html> <body> <h1>Request Processed Successfully</h1> </body> </html>
The PUT method is used for requesting that the server store the included entity-body at a location specified by the given URL. The example below asks the server to save the specified entity-body in hello.htm at the server root:
PUT /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.tutorialspoint.com Accept-Language: en-us Connection: Keep-Alive Content-type: text/html Content-Length: 182
<html> <body> <h1>Hello, World!</h1> </body> </html>
This method asks the server to remove a file at a location specified by the URL in question. The example below demands that the server remove the first.htm file at the server's root:
DELETE /first.htm HTTP/1.1
User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)
Host: www.phptpoint.com
Accept-Language: en-us
Connection: Keep-Alive
After the above example, the server will delete the first.htm file, and it will also send the response back to the client, which is as follows:
HTTP/1.1 200 OK
Date: Wed, 4 Dec 2019 5:15:40 GMT
Server: Apache/2.4. 41 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html> <body> <h1>URL deleted</h1> </body> </html>
The client uses this method. It establishes network connection over HTTP to a web server. The example below requests a connection to a web server running on the host phptpoint.com:
CONNECT www.phptpoint.com HTTP/1.1
User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)
The following example shows that the connection is established with the server, and the response is sent back to the client:
HTTP/1.1 200 Connection established
Date: Wed, 4 Dec 2019 5:15:40 GMT
Server: Apache/2.4. 41 (Win32)
The client uses this method. It is used to find out which HTTP methods and other options a web server supports. The example below requests a list of methods which a web server running on phptpoint.com supports:
OPTIONS * HTTP/1.1
User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)
In the below example, the server will send information which is based on the current configuration of the server:
HTTP/1.1 200 OK
Date: Wed, 4 Dec 2019 5:15:40 GMT
Server: Apache/2.4. 41 (Win32)
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Type: httpd/unix-directory