Welcome   |  ASP.NET   |  Web Services   |  How Do I...?   |  Class Browser  | WPF Quick Starts
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

How Do I...Make a POST request?

This sample illustrates how to use the WebRequest and WebResponse classes to make a POST request on a URI.

This sample is similar to a simple WebRequest with a GET verb. The are two differences here:

1) The verb needs to be changed to be POST.

2) The form information needs to be encoded and sent up the stream.

To change the verb, simply set the Method property to "POST".

You must then set the ContentType property to "application/x-www-form-urlencoded". At this point, make sure that the string you supply is encoded correctly, and everything will be POSTed correctly.

When you're done with the response stream you must make sure to call the Close method of the WebResponse object to avoid leaking valuable system resources.

Example

C# ClientPOST.exe
View Source

[This sample can be found at M:\web\users\sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\net\WebRequests\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2010  Mindcracker LLC. All Rights Reserved