+3 votes
190 views
in Technical issues by (242k points)
reopened
HTTP Request: the request methods you should know

1 Answer

+4 votes
by (1.6m points)
edited
 
Best answer

GET
POST
HEAD
OPTIONS
TRACE
Special methods
URL parameters
Request stream URL encoding

image

HTTP Request: the request methods you should know

On the web, clients, such as a browser, for example, communicate with different web servers with the help of the HTTP protocol, which regulates how the client has to formulate its requests and how the server has to respond. The HTTP protocol employs several different request methods. In this guide you will know the details of the most common ones..

Index
  1. GET
    1. URL parameters
    2. Request stream URL encoding
  2. POST
  3. HEAD
  4. OPTIONS
  5. TRACE
  6. Special methods

GET

GET is the mother of all HTTP requests. This request method existed as early as the world wide web and is used to request a resource , such as an HTML file, from the web server .

When you type the URL www.example.com into your browser, it connects to the web server and sends it a GET request:

  GET /index.php  

The index.php file in this request code sample is the home page of a website, which the server will send in response to the browser..

The request for the address www.example.com/test.html would be formulated in the same way:

  GET /test.html  

The server would send the file test.html as a response.

URL parameters

More information can be added to the GET request , with the intention that the web server also processes it. These so-called URL parameters are attached to the URL. The syntax is quite simple:

  • The query string starts with a question mark ???.
  • All parameters are made up of a name and a value:? Name = Value ?.
  • If several parameters are to be attached, they are joined with a? & ?.

Let's see it with this example: to search for certain offers on the website of a software company, the GET request will indicate? Windows? as a platform and? Office? as a category:

  GET /search?platform=Windows&category=office  

Request stream URL encoding

Request sequences need special encoding, because many special characters have different meanings. For example, the text? HTTP List? It must be encoded as follows to be accepted as a request sequence:

  GET /search?thema=Lista%20HTTP  
advice

It is very easy to encode URLs with online tools, such as this URL decoder, or offline with Excel's URLCODIF function ..

POST

When large packets of data, such as images or private form data, for example, have to be sent to the web server, the GET method falls short, because all the data that is transmitted is written open in the address bar of the browser.

In these cases, the POST method is used. This method does not write the URL parameter in the URL, but rather appends it to the HTTP header.

POST requests are often used with digital forms . Below you will find an example of a form that collects a name and an email address and sends it to the server via POST:

  <html> <body> <form action="newsletter.php" method="post"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br> <input type="submit"> </form> </body> </html>  
advice

In our guide you will find information to understand the difference between GET and POST.

HEAD

The HTTP HEAD request method is used to request that the server only send the response header, without the file. This alternative is convenient when very large files have to be transferred, since, with this request, the client first knows the size of the file in order to later decide whether to accept it or not.

For example:

  HEAD /downloads/video1.mpeg HTTP/1.0  

In the header that the server sends in response, the client finds the data about the file size in the? Content-length? Field:

image
The server responds to the HEAD request with key data about the file in question.

OPTIONS

With the OPTIONS method, the client can ask the server what methods it supports for the file in question.

  OPTIONS /download.php  

The answer could be something like this:

image
Server response to OPTIONS request

In the field? Allow? the server informs the client that it supports the OPTIONS, GET, HEAD and POST methods. In the? Content-length? Field, the figure 0 indicates that no file has been sent, only the header.

TRACE

With the TRACE method, you can follow the path that an HTTP Request follows to the server and from there back to the client. This trace can be run on Windows with the tracert command . You just have to enter the following command in the console ( cmd.exe ):

  tracert www.example.com  

Special methods

Some methods can only be applied in certain contexts. This is the case with the CONNECT method, which creates a direct and protected connection through a proxy ( tunneling ), or several methods that are related to WebDAV: PATCH, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK.

PUT, PATCH, and DELETE are used to save , modify, or delete files on the server . In common web programming, these methods play little role, as the server blocks them for security, but they are used in the context of WebDAV and REST APIs.


...