Tuesday, November 12, 2013

HTTP, Fiddler, and Telnet

HTTP is the "language" that browsers (clients) use to communicate with web servers.  Browsers send "request" messages to the web server.  The web server sends back "response" messages to the browser.  Each message consists of:

  1. An initial line that summarizes the message.
  2. A "headers" section that contains helpful information about the message.
  3. The body of the message.

The intial line of a request contains the "verb".  HTTP consists of only a handful of verbs that tell the web server what kind of request they are making.  GET is the most popular request made by a browser.  The browser is requesting a particular resource (html, image, other file, etc.) which is specified in the initial line of the message by indicating its URL.

The intial line of a response contains a status code and a very short description.  For example, "HTTP/1.1 200 OK".  The body of a response contains the actual resource.  For example, it would contain the html if that is what was requested.

You can actually see these messages going back and forth with a little program called Fiddler.  Just download Fiddler, install it, and run it.  If you type in a URL in a browser, you will see the corresponding GET request message in Fiddler.  Click on the Inspectors tab to see the initial line and "headers".

If you want to see the response messages, you have to download an add on called Syntax Highlighting AddOns.  There should be a link below the box that displays the details of the request message.  Once you install this, add on, you can see the details of the response for each request.  Pretty cool.

Going a step further, you can make GET requests manually independent of a browser by using Telnet.  By default, in Windows 7, Telnet is not enabled.  You have to go into Control Panel and Add/Remove Windows Features.  Enable the Telnet Client.  Then, just open up a command prompt and type as an example:

Telnet localhost 3405

-Ctrl ]-

set localecho

-Enter-

-Enter again-

GET /test.html HTTP/1.1
Host: localhost

-Enter-

-Enter again-

Now you see the response message from the web server.

Pretty cool.

Here's a good link to some helpful (if a bit dated) info on HTTP:
http://www.jmarshall.com/easy/http/

No comments:

Post a Comment