c# http request example

Example 1: https request c#

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://requestbin.net/r/xxxxxxxx?" + textBox2.Text);
req.GetResponse();

Example 2: c# make http request

private static readonly HttpClient client = new HttpClient();

var responseString = await client.GetStringAsync("http://www.example.com/recepticle.aspx");

Example 3: how make a post request c#

//You can aquire RestSharp from Nuget package manager
  RestClient restClient = 
  new RestClient(string.Format("{0}/myservice/api/endpoint", "https://exampledomain.com:88"));
  RestRequest request = new RestRequest(Method.POST);
  request.RequestFormat = DataFormat.Json;
  request.AddJsonBody(data); //data is C# model for post request
  request.AddHeader("Accept", "application/pdf");
  var result = restClient.Execute(request);