Below is a sample code snippet demonstrating the usage of the WebClient to post data to the server in C#.
How to Post data to a URL using WebClient in C# ?
using System; using System.Collections.Generic; using System.Linq; using System.Net; namespace ACCode { class Program { static void Main(string[] args) { string Uri = "http://www.abundantcode.com/post.php"; string params1 = "author=GoogleMVP"; using (WebClient webClientInstance = new WebClient()) { webClientInstance.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; string result = webClientInstance.UploadString(Uri, params1); Console.WriteLine(result); } Console.ReadLine(); } } }
Leave a Reply