As you may know, the POST method embeds the contents inside the stream itself, but the way this vars are actually structured can be very similar to the query string /GET method.
We are using a HttpWebRequest object to configure a web request, we are also setting the method to POST, last but absolutely not least, we are adding a header in the request to tell we are actually posting data url encoded.
This means, our data can be like this:
In this example, we are assuming we want to loging to a website, and this webside actually use some kind of cookie based authentication mechanism, this is why we are using a CookieContainer.
Later on, if you want to do some other request, and you need the site remembers you, you can actually pass in the same CookieContainer to the next requests.
But anyway, back to the subject:
First, We are getting a byte array from our post var data, and encoding it using UTF8. (extended ASCII support for special chars)
Then, we just tell the response the length of our content, which is the same of our post data string. Then:
We are getting the request byte stream, then writing the POST data inside it.
Then, we just need to get the response (action that will perform the request we just configured before).
After this, we may want to get the response text to do some actions with it