What, at the bare minimum, is required for an HTTP request?

if the request is: "GET / HTTP/1.0\r\n\r\n" then the response contains header as well as body, and the connection closes after the response.

if the request is:"GET / HTTP/1.1\r\nHost: host:port\r\nConnection: close\r\n\r\n" then the response contains header as well as body, and the connection closes after the response.

if the request is:"GET / HTTP/1.1\r\nHost: host:port\r\n\r\n" then the response contains header as well as body, and the connection will not close even after the response.

if your request is: "GET /\r\n\r\n" then the response contains no header and only body, and the connection closes after the response.

if your request is: "HEAD / HTTP/1.0\r\n\r\n" then the response contains only header and no body, and the connection closes after the response.

if the request is: "HEAD / HTTP/1.1\r\nHost: host:port\r\nConnection: close\r\n\r\n" then the response contains only header and no body, and the connection closes after the response.

if the request is: "HEAD / HTTP/1.1\r\nHost: host:port\r\n\r\n" then the response contains only header and no body, and the connection will not close after the response.


It must use CRLF line endings, and it must end in \r\n\r\n, i.e. a blank line. This is what I use:

printf 'GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n' |
  nc www.example.com 80

Additionally, I prefer printf over echo, and I add an extra header to have the server close the connection, but those aren’t needed.


See Wiki: HTTP Client Request (Example).

Note the following:

A client request (consisting in this case of the request line and only one header) is followed by a blank line, so that the request ends with a double newline, each in the form of a carriage return followed by a line feed. The "Host" header distinguishes between various DNS names sharing a single IP address, allowing name-based virtual hosting. While optional in HTTP/1.0, it is mandatory in HTTP/1.1.

The absolute minimum (if removing the Host is allowed ;-) is then GET / HTTP/1.0\r\n\r\n.

Happy coding


I was able to get a response from my Apache server with only the requested document, no response header, with just

GET /\r\n

If you want response headers, including the status code, you need one of the other answers here though.


The fact of the 400 Bad Request error itself does not imply that your request violates HTTP. The server very well could be giving this response for another reason.

As far as I know the absolute minimum valid HTTP request is:

GET / HTTP/1.0\r\n\r\n