Most protocols have libraries and tools available to abstract away the
However, if you’re a full-stack developer, you’ll have used
telnet to talk a protocol directly, and it’s very likely to have
been HTTP. It’s a textual request/response protocol.
$ telnet www.apache.org 80
Wait for a connection:
Trying 18.104.22.168... Connected to www.apache.org. Escape character is '^]'.
Then type the request and wait for a response and for the server to close the socket:
Connection closed by foreign host.
Any further sophistication is opt-in and can be ignored for now.
From HTTP 0.9, back in 1991, it’s easy to make a request:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://any23.apache.org">here</a>.</p> </body></html>
GET / HTTP/1.0
HTTP/1.1 301 Moved Permanently Date: Fri, 02 Jan 2015 05:40:17 GMT Server: Apache/2.4.7 (Ubuntu) Location: http://any23.apache.org Content-Length: 231 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://any23.apache.org">here</a>.</p> </body></html>
HTTP 0.9’s obsolesence was formally recognised in RFC 7230 (2014), which explicitly dropped the requirement to support HTTP 0.9:
The expectation to support HTTP/0.9 requests has been removed. (Appendix A)
(apache.org was the first site I tried which still accepted and responded with 0.9.)
HTTP/1.1 was introduced in RFC 2068 (1997), refined in RFC 2616 (1999) and then majorly refined in RFC 7230-7235 (2014). A new header became mandatory:
GET / HTTP/1.1 Host: www.apache.org
HTTP/1.1 200 OK Date: Fri, 02 Jan 2015 05:49:16 GMT Server: Apache/2.4.7 (Ubuntu) Last-Modified: Fri, 02 Jan 2015 05:10:41 GMT ETag: "a120-50ba45cb03985" Accept-Ranges: bytes Content-Length: 41248 Vary: Accept-Encoding Cache-Control: max-age=3600 Expires: Fri, 02 Jan 2015 06:49:16 GMT Content-Type: text/html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Welcome to The Apache Software Foundation!</title>
Twenty-three years of evolution has introduced a couple more things to
remember when we
telnet in, with one of them being optional.
After sixteen drafts (and four major versions over three years at Google in its SPDY incarnation), HTTP/2 has moved to Last Call (W3C Recommendation Track Process - Last Call Announcement).
That’s dangerously close to being the current version of arguably the most important protocol on the Internet. Even if I’m going to be using it through libraries and browsers, I should at least know how to craft a basic request and parse a response.