Telnet HTTP

To connect to a web server using telnet:

$ telnet example.com 80

At this point, you must type your web request:

GET /index.html HTTP/1.1
Host: example.com

This requests the webpage index.html from the webserver using HTTP version 1.1 for the hostname example.com.

Afterwards, press the enter key twice. You should a response similar to the one below:

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 14
Content-Type: text/html
Date: Tue, 12 Nov 2024 06:19:33 GMT
Last-Modified: Tue, 12 Nov 2024 06:15:19 GMT
Server: OpenBSD httpd

<!DOCTYPE html>                                                                                        
<html>
<head>
<meta charset="utf-8">
<title>Hello, world!</title>
...
Connection closed by foreign host.

If the web server does not want to serve port 80, it may forward you to port 443 using a 302 redirect as shown below:

HTTP/1.0 302 Found
Date: Tue, 23 Feb 2021 14:01:28 GMT
OpenBSD httpd
Connection: close
Content-Type: text/html
Content-Length: 486
Location: https://example.com/index.html

<!DOCTYPE html>
<html> 
<head>
<meta charset="utf-8"> 
<title>302 Found</title>
<style type="text/css"><!--
body { background-color: white; color: black; font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }
hr { border: 0; border-bottom: 1px dashed; }
@media (prefers-color-scheme: dark) {
body { background-color: #1E1F21; color: #EEEFF1; }
a { color: #BAD7FF; }
}
--></style>
</head>
<body>
<h1>302 Found</h1>
<hr>
<address>OpenBSD httpd</address>
</body>
</html>
Connection closed by foreign host.