Posting Data

There might be many times when you want to include data in your Web request that must be posted to a remote server. This is likely to include form data that you want to post to a server, and this form data must be processed before any data can be returned. The code in Listing 26.7 shows you how to add POST data to your WebRequest.

Listing 26.7. This Code Shows How to Post Data in a Request
 try { WebRequest req = WebRequest.Create( strURL ); req.Method = “POST”; req.ContentType = “application/x-www-form-urlencoded”; byte[] SomeBytes = null; SomeBytes = Encoding.UTF8.GetBytes( strPostData ); req.ContentLength = SomeBytes.Length; Stream newStream = req.GetRequestStream(); newStream.Write( SomeBytes, 0, SomeBytes.Length ); newStream.Close(); ...

Get Special Edition Using® Microsoft® ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.