There are several ways to perform HTTP GET and POST requests:
Method A: HttpClient
Available in: .NET Framework 4.5+, .NET Standard 1.1+, .NET Core 1.0+
Currently the preferred approach. Asynchronous. Portable version for other platforms available via NuGet.
using System.Net.Http;
Setup
It is recommended to instantiate one HttpClient for your application's lifetime and share it.
private static readonly HttpClient client = new HttpClient();
POST
var values = new Dictionary<string, string>
{
{ "name", "nanumtip" },
{ "domain", "nanumtip.com" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://www.nanumtip.com/qa/ask", content);
var responseString = await response.Content.ReadAsStringAsync();
GET
var responseString = await client.GetStringAsync("https://www.nanumtip.com/qa/ask");