HTTP Request
HTTP Request Messages
When a web page is opened in a browser, the browser sends a request message like the following to the server.
GET / HTTP/1.1
Accept: image/gif, image/jpeg, */*
Accept-Language: ko
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1;)
Host: www.xxx.zzz
Connection: Keep-Alive
A request message consists of the following syntax.
HTTP request line
GET / HTTP/1.1
HTTP request header
Accept: image/gif, image/jpeg, */*
Accept-Language: ko
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1;)
Host: www.xxx.zzz
Connection: Keep-Alive
HTTP body
Message body (used with methods such as POST)
Start Line
The start line of an HTTP request has the following three elements.
- HTTP method
- Request target (path name)
- HTTP protocol version
The request line is displayed in the following format.
Request line
[HTTP method] [request target] [HTTP protocol version]
The path name is usually like /aaa/bbb/ccc.html, and either a path name starting with a slash or a URL starting with http:// is specified. Version 1.1 is commonly used.
HTTP Method
The methods supported by HTTP/1.0 and HTTP/1.1 are as follows.
| Method | HTTP/1.0 | HTTP/1.1 | Description |
|---|---|---|---|
| GET | ◎ | ◎ | The most commonly used method. The browser asks the server to retrieve a page. |
| HEAD | ◎ | ◎ | Requests header-only information. Servers must support GET and HEAD. |
| POST | ○ | ○ | Used to send data entered in a form with method="POST" to the server. |
| PUT | ○ | ○ | Used to upload a file to the server. |
| DELETE | ○ | ○ | Requests that the server delete the specified resource. |
| CONNECT | × | ○ | Used for SSL communication through a proxy server. |
| OPTIONS | × | ○ | Used to query the methods and options supported by the server. |
| TRACE | × | ○ | Used to trace HTTP behavior, such as which proxy servers an HTTP request passes through. The final server that receives this message returns the entity contained in the request message, usually headers plus message body, as-is. |
| LINK | ○ | × | Creates a link relationship between the specified URL and resource. No longer used in HTTP/1.1. |
| UNLINK | ○ | × | Removes the link relationship between the specified URL and resource. No longer used in HTTP/1.1. |
(◎: required, ○: supported, ×: not supported)
Apache also supports methods such as PATCH, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, and UNLOCK.
GET
The GET request method asks the server to retrieve information held by a URI (URL).
Transmission format
GET [request-uri]?query_string
HTTP/1.1\r\n
Host: [Hostname] or [IP] \r\n
POST
The POST request method is used when form input is processed by a server-side script such as ASP, PHP, JSP, or a CGI program configured for the request URI (URL). It is sent together with the form action, and the request information is placed in the data part rather than in the header.
Transmission format
POST [request-uri]?query_string
HTTP/1.1\r\n
HOST:[Hostname] or [IP] \r\n
Content-Length:[Length in Bytes] \r\n
\r\n
[query-string] or [data]
HEAD
The HEAD request method is similar to GET, but the web server sends no data other than header information.
It can be used to check whether a web server is down (health check) or to obtain web server information such as its version.
Transmission format
HEAD [request-uri] HTTP/1.1\r\n
Host: [Hostname] or [IP] \r\n
OPTIONS
rfc2616
This method can be used to check which methods are supported by the system.
Transmission format
OPTIONS [request-ri]
HTTP/1.1\r\n
Host: [Hostname] or [IP] \r\n
PUT
Because it has a transmission structure similar to POST, a message (data) is sent together with headers.
It is used to store specified content on a remote server and is often abused for website defacement.
Transmission format
PUT [request-uri] HTTP/1.1\r\n
Host: [Hostname] or [IP] \r\n
Content-Length:[Length in Bytes] \r\n
Content-Type:[Content Type] \r\n
\r\n
[data]
PATCH
PATCH is used to modify (UPDATE) the requested resource, similarly to PUT.
PUT means updating the whole resource, while PATCH means replacing part of that resource. In other words, it partially changes a resource.
Transmission format
PATCH [request-uri] HTTP/1.1\r\n
Host: [Hostname] or [IP]\r\n
Content-Length:[Length in Bytes]\r\n
Content-Type:[Content Type]\r\n
\r\n
[data]
DELETE
DELETE is used to delete a file on a remote web server and is the opposite concept of PUT.
TRACE
TRACE is used to call a loopback message on a remote server.
CONNECT
CONNECT is used to request proxy functionality from a web server.
Request Target
The request target includes URLs, paths, query strings, and similar values.
| Request target form | Example | Description |
|---|---|---|
| origin form | - POST / HTTP/1.1 - GET /background.png HTTP/1.0 - HEAD /test.html?query=alibaba HTTP/1.1 - OPTIONS /anypage.html HTTP/1.0 |
Common form |
| absolute form | GET http://developer.mozilla.org/en-US/docs/Web/HTTP/Messages HTTP/1.1 | Used when doing GET through a proxy |
| authority form | CONNECT developer.mozilla.org:80 HTTP/1.1 | Used with CONNECT |
| asterisk form | OPTIONS * HTTP/1.1 | Used with OPTIONS |
HTTP Protocol Version
Indicates the HTTP version. Usually HTTP/1.1 or 2.0.
HTTP Header
There are three types of request headers.
| Header type | Description | Examples |
|---|---|---|
| Request header | Headers not related to the data in the request body | - Host - User-Agent - Accept - - If- - Referer |
| General header | Resource to retrieve | - Date - Cache-Control |
| Entity header | Applies to the request body | - Content-Type - Content-Length - Expires |
HTTP Body
The HTTP request body is the data sent with the request.
In general, GET, HEAD, DELETE, and OPTIONS do not have request bodies. They are used only when retrieving or deleting resources.
The request body is used when sending data to a resource with POST, PUT, and similar methods.
Checking a request body
% curl --trace-ascii - http://www.devkuma.com/ -XPOST -d 'user=kimkc,password=1234'
=> Send data, 24 bytes (0x18)
0000: user=kimkc,password=1234