http post method in c# code example
Example 1: c# post get request
using System.Net.Http;
HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();
var responseString = await client.GetStringAsync("http://www.example.com/recepticle.aspx");
Example 2: how to POST in c#
using System;
using System.Collections.Specialized;
using System.Net;
namespace API_Console_App
{
class Program
{
static void Main(string[] args)
{
string url = "URL_HERE";
WebClient client = new WebClient();
NameValueCollection values = new NameValueCollection();
values.Add("data-name", "content");
client.UploadValues(url, values);
}
}
}