Demo it now
Oftentimes, such as when hacking demos, we want our client side app talking to some form backend without spending too much time on it. One way to do it in a Microsoft environment is to do a quick
POST request using
HTTPWebRequest does exactly what the name suggests and saves us a lot of time from having to write our own HTTP calls.
As simple as URL
During the first step, we would split our URL such as
http://www.someserver.com/service.aspx?var1=val1.. into the address
of the server and the body containing our POST variables. Of course, if we were creating a GET request, then we would not need to do that.
Next, we would create
HTTPWebRequest object using the above uri in the constructor and assign whichever HTTP header variables we need.
Since we are POSTing to some form backend, we would also need to tell the server that we are submitting a form:
And finally, since we are sending a POST request, our URL GET variables will go into the body of our HTTP request.
The whole HTTP request
P.S. And what about the response?
To obtain the response from the server, we would simply use
HTTPWebResponse object and use StreamReader to get the body of the response.