26 bytes
for an exceptional case, a 1-byte resource and a 1-byte hostname.
GET / HTTP/1.1<CR><LF> Host:x<CR><LF> <CR><LF>
You need the start line of the request and, if you are using HTTP 1.1, the Host header. Each new line is two bytes (CRLF). The two parts of this minimum GET request are variables: the path to the resource and the host name.
The minimum initial request line is GET / HTTP/1.1 , which is 16 bytes (including two invisible CRLF bytes that you cannot see).
The minimum host string is Host:x , that is, a single-byte host name that gives 8 bytes (again, two CRLF bytes).
To mark the end of the headers, you need another CRLF, so there are 2 more bytes.
16+8+2=26 bytes for the minimum size of an HTTP request.
Of course, this increases if you have a longer host name or a longer path to the resource. To take this into account, the minimum HTTP request size is 24 + length(resource_path) + length(host)
Here is a real bash netcat example (note that the resource path and hostname are longer than the minimum):
nc -c www.example.com 80 <<EOF GET /index.html HTTP/1.1 Host:www.example.com EOF
Doug richardson
source share