HTTP Methods

For HTTP/1.1, the set of common methods are defined below. This set can be expanded based on the requirements. The name of these methods is case sensitive, and they must be used in uppercase.

Method and Description

i) GET

This method retrieves information from the given server using a given URI. GET request can retrieve the data. It can not apply other effects on the data.

ii) HEAD

This method is the same as the GET method. It is used to transfer the status line and header section only.

iii) POST

The POST request sends the data to the server. For example, file upload, customer information, etc. using the HTML forms.

iv) PUT

The PUT method is used to replace all the current representations of the target resource with the uploaded content.

v) DELETE

The DELETE method is used to remove all the current representations of the target resource, which is given by URI.

vi) CONNECT

This method establishes a tunnel to the server, which is identified by a given URI.

vii) OPTIONS

This method describes the options of communication for the target resource.

GET Method

This method is used to retrieve data from a web server using the specifying parameters in the URL portion of the request. This is the main method that is used for document retrieval. The use of the GET method to fetch first.htm is as follows:

  1. GET /first.htm HTTP/1.1  
  2. User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)  
  3. Host: www.javatpoint.com  
  4. Accept-Language: en-us  
  5. Accept-Encoding: gzip, deflate  
  6. Connection: Keep-Alive  

The following are the server response against the above GET request:

  1. HTTP/1.1 200 OK  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  
  4. Last-Modified: Mon, 2 Dec 2019 15:40:30 GMT  
  5. ETag: "34aa387-d-1568eb00"  
  6. Vary: Authorization,Accept  
  7. Accept-Ranges: bytes  
  8. Content-Length: 55  
  9. Content-Type: text/html  
  10. Connection: Closed  
  1. <html>  
  2. <body>  
  3. <h1> First Program</h1>  
  4. </body>  
  5. </html>  

HEAD Method

This method is the same as the GET method. But in the HEAD method, the server replies with a response line and headers without entity-body. The use of HEAD method to fetch header information about first.htm is as follows:

  1. HEAD /first.htm HTTP/1.1  
  2. User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)  
  3. Host: www.javatpoint.com  
  4. Accept-Language: en-us  
  5. Accept-Encoding: gzip, deflate  
  6. Connection: Keep-Alive  

The following are the server response against the above HEAD request:

  1. HTTP/1.1 200 OK  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  
  4. Last-Modified: Mon, 2 Dec 2019 15:40:30 GMT  
  5. ETag: "34aa387-d-1568eb00"  
  6. Vary: Authorization,Accept  
  7. Accept-Ranges: bytes  
  8. Content-Length: 55  
  9. Content-Type: text/html  
  10. Connection: Closed  

Here, we can see that the server does not send any data after the header.

POST Method

This method is used to send some data to the server, for example, update files from data, etc. The use of POST method to send a form data to the server is as follows:

  1. POST /cgi-bin/process.cgi HTTP/1.1  
  2. User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)  
  3. Host: www.jsvatpoint.com  
  4. Content-Type: text/xml; charset=utf-5  
  5. Content-Length: 55  
  6. Accept-Language: en-us  
  7. Accept-Encoding: gzip, deflate  
  8. Connection: Keep-Alive  
  1. <"xml version="1.0" encoding="utf-5">  
  2. <string xmlns=" https://www.javatpoint.com/">string</string>  

The script of server side process.cgi processes the passed data and sends the response which is as follows:

  1. HTTP/1.1 200 OK  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  
  4. Last-Modified: Mon, 2 Dec 2019 15:40:30 GMT  
  5. ETag: "34aa387-d-1568eb00"  
  6. Vary: Authorization,Accept  
  7. Accept-Ranges: bytes  
  8. Content-Length: 55  
  9. Content-Type: text/html  
  10. Connection: Closed  
  1. <html>  
  2. <body>  
  3. <h1> Request Processed Successfully</h1>  
  4. </body>  
  5. </html>  

PUT Method

This method requests the server to store the included entity-body at a location that is specified by the given URL. The below example requests the server to save the given entity-body in first.htm at the root of the server.

  1. PUT /first.htm HTTP/1.1  
  2. User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)  
  3. Host: www.javatpoint.com  
  4. Accept-Language: en-us  
  5. Connection: Keep-Alive  
  6. Content-type: text/html  
  7. Content-Length: 150  
  1. <html>  
  2. <body>  
  3. <h1> First Program</h1>  
  4. </body>  
  5. </html>  

In first.htm file, the server will store the given entity-body, and it will also send the following response back to the client:

  1. HTTP/1.1 201 Created  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  
  4. Content-type: text/html  
  5. Content-length: 30  
  6. Connection: Closed  
  1. <html>  
  2. <body>  
  3. <h1> The file was created.</h1>  
  4. </body>  
  5. </html>  

DELETE Method

This method requests the server to delete a file at a location that is specified by the given URL. The below example requests the server to delete the first.htm file at the root of the server:

  1. DELETE /first.htm HTTP/1.1  
  2. User-Agent: Mozilla/69.0 (compatible; MSIE5.01; Windows 10)  
  3. Host: www.javatpoint.com  
  4. Accept-Language: en-us  
  5. 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:

  1. HTTP/1.1 200 OK  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  
  4. Content-type: text/html  
  5. Content-length: 30  
  6. Connection: Closed  
  1. <html>  
  2. <body>  
  3. <h1>URL deleted</h1>  
  4. </body>  
  5. </html>  

CONNECT Method

This method is used by the client. It establishes a network connection to a web server over HTTP. The below example requests a connection with a web server which is running on the host javatpoint.com:

  1. CONNECT www.javatpoint.com HTTP/1.1  
  2. 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:

  1. HTTP/1.1 200 Connection established  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  

OPTIONS Method

This method is used by the client. It is used to find out the HTTP methods and other options that are supported by a web server. The below example requests a list of methods which is supported by a web server which is running on javatpoint.com:

  1. OPTIONS * HTTP/1.1  
  2. 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:

  1. HTTP/1.1 200 OK  
  2. Date: Wed, 4 Dec 2019 5:15:40 GMT  
  3. Server: Apache/2.441 (Win32)  
  4. Allow: GET,HEAD,POST,OPTIONS,TRACE  
  5. Content-Type: httpd/unix-directory