HTTP HTTP Overview (from Mozilla Developer Network) has most of what we need to know about HTTP the protocol handling all things web.
If you click on a link, or if you write an url in the appropriate field in you browser you are actually issuing a request to a server to bring you the url in question. This request is handled by HTTP. It has help from other protocols, but hey are transparent to you. The server eventually receives the request, and will most likely return a response to you. The requests and responses are transferred across the internet by HTTP.
If you wrote web pages before, you have interacted with
HTTP before. Take HTML5 forms. They are written with a
method, and an action field.
<form action="http://x15.dk/hitme.php" method="post">
...
</form>
In the example the value of the action attribute
is the url of the server to whom HTTP submits the user
entered form data.
NMLProbook ~ $telnet x15.dk 80Trying 91.221.196.226... Connected to x15.dk. Escape character is '^]'.GET /telnetTest.html HTTP/1.1 HOST: x15.dkHTTP/1.1 200 OK Date: Thu, 16 Jan 2020 15:00:27 GMT Server: Apache Last-Modified: Thu, 16 Jan 2020 14:54:01 GMT Accept-Ranges: bytes Content-Length: 176 Content-Type: text/html <!doctype html> <html> <head> <meta charset="utf-8"/> <title>HTTP Test Page</title> </head> <body> <h1>Hello World!</h1> </body> </html>Connection closed by foreign host. NMLProbook ~ $
In lines 5 and 6 of the code above you see the actual HTTP request being issued.
The host address must be followed by two newlines in order to send the request. This really means that a request ends with an empty line. The response follows after the empty line and as all HTTP packages it consists of two parts, a header and a body.
The header fields describing the body's content, and the the actual content of the body are referred to as the payload of the package.
The following methods exist, and with semantics as this quote from RFC7231:
+---------+-------------------------------------------------+-------+
| Method | Description | Sec. |
+---------+-------------------------------------------------+-------+
| GET | Transfer a current representation of the target | 4.3.1 |
| | resource. | |
| HEAD | Same as GET, but only transfer the status line | 4.3.2 |
| | and header section. | |
| POST | Perform resource-specific processing on the | 4.3.3 |
| | request payload. | |
| PUT | Replace all current representations of the | 4.3.4 |
| | target resource with the request payload. | |
| DELETE | Remove all current representations of the | 4.3.5 |
| | target resource. | |
| CONNECT | Establish a tunnel to the server identified by | 4.3.6 |
| | the target resource. | |
| OPTIONS | Describe the communication options for the | 4.3.7 |
| | target resource. | |
| TRACE | Perform a message loop-back test along the path | 4.3.8 |
| | to the target resource. | |
+---------+-------------------------------------------------+-------+
Here we describe the HTTP methods, and the significance of their payloads:
From your previous lives you are familiar with at least the GET and POST methods of the HTTP. They are used whenever we create an HTML5 form Example 15.22. Irrespective of which of the two methods we use, data are send in the format:
var1=value1&var2=value2&var3=Kilroy%20was%20here
If the method is POST, this so called query
string is placed in the body of the HTTP
package and considered part of the payload.
If, on the other hand, the method is GET, the
query string is concatenated to the url of the package
signified by a ? (question mark.) In
this case it is not considered part of the payload, and
it is your responsibility as the developer to cater for its
use.
http://x15.dk/hitme.php?var1=value1&var2=value2&var3=Kilroy%20was%20here
It is possible to attach a query string to any HTTP package, irrespective of method, but again, you are responsible for its use. There's is no built in action.