Check out a free preview of the full Networking and Streams course

The "HTTP Post" Lesson is part of the full, Networking and Streams course featured in this preview video. Here's what you'd learn in this lesson:

James demonstrates how HTTP Post is used to send information through forms.


Transcript from the "HTTP Post" Lesson

>> If we want to send a post request instead of a get request, we can send a message looks like this. So instead of the get HTTP verb, we use the post verb. And so I think that you have to remember is that I guess some servers really don't like it if you don't specify the content type.

So this is the content type, which is pretty nasty and hard to remember, but it means that the server is going to interpret this kind of string correctly. So the post says, just like the get example, that the host is localhost. Content length is 51 bytes which refers to the length of this string right here.

And that it's this kind of formatted string. So here I have a little server written in Node.js that uses the body module from npm to do, to parse the form data, and it's also going to print out the request method, the request URL and the headers, which is misspelled, so that won't work.

But anyways, we should see something like this in addition to the examples so if we go ahead and do that, so here I can run the server I'm gonna fix that typo really quick. So here we can run the server. And I have the post right here in a text file.

So that's the same from the slides, and I can send it to netcat. So I'm going to do netcat localhost. Send that post file. And here we go, we can see that the server got a post request to slash form and here are the headers that it saw.

And then it parsed the, the body that we sent in our request to generate this object. So you can do all kinda things with that information. You can take off pieces of that object and like interpret usernames and sessions and whatever you like. Okay, I'm gonna put that in the git report.

So that So that people can play around. Okay, and then another important thing to know is that we should get back something from the server that looks like this. So from netcat, we got back these headers from the HTTP server status code of 200, which means this request is good.

And I have the server says and I have something for that document. The important thing to note is that this header transfer encoding chunked is kinda an alternative to the content link header, it means that the server is gonna send back these links for each of these chunks.

So just like just like a packets are kinda chopped up into little pieces. This way the server doesn't have to know how much data it's going to send. So if it has something that might take a variable amount of information that it doesn't quite know, in advance how long the response that it's gonna send then it can use this method.

So these are encoded I think in hex and little data payloads. And then if there is more data, it would have a new number on its own line. But when it's when the request is finished, it prints out a zero which is kind of like the end. No more data.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now