Notifications
Clear all

Send data using http POST method in C#  

   RSS

1

How can I make a HTTP request and send some data using the POST method in C# .Net?

Topic Tags
1 Answer
1

There is a wrapper HttpClient around HttpWebRequest
Available from: .NET Framework 4.5+, .NET Standard 1.1+, .NET Core 1.0+

//include necessary Package
using System.Net.Http;

//Instantiate HttpClient
private static readonly HttpClient client = new HttpClient();

//Prep data
var data = new Dictionary<string, string>
{
{ "data1", "hello" },
{ "data2", "world" }
};

//Code to POST data
var postData = new FormUrlEncodedContent(data);
var response = await client.PostAsync("http://www.url.com/posthandler.aspx", postData);
var responseString = await response.Content.ReadAsStringAsync();
Share:
Share this
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •