views:

1209

answers:

1

Lets say we have a web page with a search input form, which submits data to server via HTTP GET. So that's mean server receive search data through query strings. User can see the URL and can also initialize this request by himself (via URL + Query strings).

We all know that. Here is the question.

What if this web page submits data to the server via HTTP POST? How can user initialize this request by himself?

Well I know how to capture HTTP POST (that's why network sniffers are for), but how can I simulate this HTTP POST request by myself in a C# code?

+6  A: 

You could take a look at the WebClient class. It allows you to post data to an arbitrary url:

using (var client = new WebClient())
{
    var dataToPost = Encoding.Default.GetBytes("param1=value1&param2=value2");
    var result = client.UploadData("http://example.com", "POST", dataToPost);
    // do something with the result
}

Will generate the following request:

POST / HTTP/1.1
Host: example.com
Content-Length: 27
Expect: 100-continue
Connection: Keep-Alive

param1=value1&param2=value2
Darin Dimitrov