Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
HTTP Requests Using Telnet7:08 with Chris Ramacciotti
In this video, we'll get a firsthand, unobscured look at HTTP requests and responses using a command-line tool called Telnet.
Installing Telnet Client - OSX
If you're using a Mac, Telnet should be installed and enabled. Simply open a terminal and execute some of the commands used in this video.
Installing Telnet Client - Windows
Depending on your version of Windows, you may already have it installed, and you simply need to enable it. Opening PowerShell and attempting to use Telnet will reveal whether or not you'll need to install.
Try executing some of the commands we use in the video. If they aren't recognized, then you'll need to either enable or install Telnet. Here are a couple resources based on those two scenarios:
Installing Telnet Client - Linux
It's possible that Telnet is already installed and ready to use in your terminal. If not, search for instructions on your specific distribution. Depending on the package management utility you use, you may be able to install with
So that we can get the most basic, no frills to look at HTTP, 0:00 we'll use some text-based interactions. 0:04 HTTP is a plain text protocol, which means that messages sent using HTTP 0:07 are directly readable, kinda like a text file on your computer. 0:11 A great piece of software to use for this purpose is called Telnet. 0:16 Telnet is a little piece of software that's designed for connecting to and 0:21 communicating with a remote device. 0:25 With Telnet, you aren't limited to communicating using HTTP, but 0:27 that's what we're gonna focus on here. 0:31 Let's get started. 0:34 You can install Telnet on your local machine if you like. 0:36 And there's plenty of instruction out there to get you going. 0:39 Check the teacher's notes for more. 0:41 Fortunately, you also have Telnet available to you in workspaces. 0:43 So, even though I'll be demonstrating the work in my terminal, you'll be able to do 0:46 the same using the console on the workspace that's linked to this video. 0:50 We'll be connecting with a web server at httpbin.org using Telnet, 0:54 httpbin.org is a service specifically designed for 0:59 testing HTTP requests and seeing the resulting responses. 1:03 To connect with this server using Telnet, I'll start by issuing the Telnet command. 1:06 Followed by the name of the host that we wanna connect to httbin.org, 1:11 followed by the port number. 1:16 This 80 is for port 80, and indicates a specific type of communication that will 1:18 happened with the device we're connecting to. 1:23 In our case, the type of communication that will be happening is HTTP messaging. 1:26 Think about this way, the host or 1:30 domain name of httpbin.org reside at some address. 1:33 Which is the address of a specific device or server, think of this server 1:36 is a house and it's address is called the internet protocol or IP address. 1:41 Now, once we've arrive at the house, let's say that there's several 1:45 people living there and each one speaks a different language. 1:49 We only speak one language, HTTP that is. 1:51 So we'll knock on the web server's door, which is door or port 80 by default. 1:55 As long as there's somebody in port 80, that is, 2:00 there's a web server at this address, we know that the person who opens the door 2:03 also speaks our language, which again is HTTP. 2:06 Great, so I'll hit enter to connect and then I'll send a request to get the root 2:10 using HTTP protocol version 1.1, 2:15 and follow it quickly with the host again. 2:20 And I'll hit enter twice. 2:24 A couple thing here, I have to specify the host again because it turns out that 2:26 at this address of where we connected, there might be several host. 2:31 For example, GoDaddy is a web host that will put many domains or 2:35 host onto a single IP. 2:39 Listing the host again in the httprequest.sent 2:41 allows the server to route it to the proper place with in the server. 2:44 Another thing, I said you'll have to quickly follow-up with the host. 2:48 I say quickly, because while using telnet, your may timeout. 2:52 There's nothing about HTTP that requires quickness, that's just part of Telnet. 2:56 Now, let me scroll up to where I made this request and explain what I did. 3:01 I made a request to get or fetch the content that is at the root. 3:06 That's why I'm using this single slash here. 3:11 And the protocol version I'm using of HTTP is version 1.1. 3:14 This entire line here is called the request line. 3:19 Which we'll discuss more in just a bit. 3:22 Making this whole request is like navigating to httpbin.org in your browser. 3:25 The response I got here is HTML as you see down below. 3:29 And the only difference is that when a browser sees HTML, 3:34 it's rendered by what's called the browser's layout engine. 3:37 But here in terminal, there's no layout engine. 3:40 In other words, the browser knows how to read HTML and make it look presentable on 3:43 the terminal, well, the terminal is text base so it just spits out the raw HTML. 3:46 Let's scroll down and 3:51 make another request to this server, this time requesting a different resource. 3:52 So, to reconnect to the server, I will telnet again to httpbin.org at 80. 3:56 And this time I will request the resource at /xml, 4:02 again using HTTP version 1.1. 4:07 And I'll list again the host. 4:11 Press enter twice, and there's our response. 4:14 Let's go back to this request line here. 4:19 I'm requesting the resource at /xml. 4:21 You may have used this slash notation to refer to directories in the past. 4:25 And this sometimes the case when communicating with web servers, 4:29 but a slash doesn't always refer to a directory. 4:32 So be careful here. 4:35 For now, simply think of it a resource at the address /xml on the host httpbin.org. 4:36 This resource identifier has a name, 4:45 it's called quite intuitively a uniform resource identifier, abbreviated URI. 4:47 It's not quite the same thing as a URL, which is a uniform resource locator. 4:53 We'll return to the similarities and differences later on. 4:58 Now in this case, the response that came back is XML which stands for 5:01 extensible markup language. 5:06 Instead of the response we got previously which was HTML or 5:09 hypertext markup language. 5:12 Httpbin.org has several different resources that it exposes for 5:15 you to test different things. 5:18 And this is one of them. 5:21 We can test HTML responses, and we can test XML responses among others. 5:22 Now, we can't just make any request to the server and expect a great response. 5:27 Let's scroll down and try another. 5:31 Let me clear the console here to give myself a clean screen. 5:34 Let's again telnet to httpbin.org at port 80, 5:39 and let's get the resource at /treehouse using 5:43 HTTP version 1.1 and again specifying the host. 5:48 I'm gonna hit enter twice. 5:56 And it doesn't take much scanning through the response to see that the server's 5:57 telling us that there is no resource that has the identifier/treehouse. 6:02 And you've probably seen this 404_NOT_FOUND message before. 6:06 Before we bring this video to a close, 6:12 let me quickly show you how to do this in workspaces. 6:13 If you open the linked workspace, you'll see a completely empty project. 6:16 You won't need to add any files to the project but 6:21 you will need to use the console here. 6:24 If you don't see the console, simply choose View, Show Console. 6:28 When the console is hidden, this option right here will say, Show Console. 6:33 Click it and it will come right up for you. 6:36 Now you're ready to start using Telnet. 6:41 So, just as before, you could start by connecting with Telnet. 6:42 Telnet httpbin.org port 80. 6:46 And we could get the root using HTTP version 6:50 1.1 at the host httpbin.org. 6:55 And there it is. 7:00 For any other work I do in the terminal, 7:02 you'll be able to do the same in workspaces. 7:04 So the choice is yours. 7:06
You need to sign up for Treehouse in order to download course files.Sign up