How can I add Headers to an HttpWebRequest

0

I'm using

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://test.net"); 

To create a connection to the server and would like to know how I can add headers to httpWebRequest ?

    
asked by anonymous 28.08.2017 / 17:20

1 answer

3

Examples:

HttpClient:

client.DefaultRequestHeaders.Accept
          .Add(new MediaTypeWithQualityHeaderValue("application/json"));

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "xxxxxxxxxxxxxxxxxxxx");

using webRequest:

webRequest.Headers.Add("Authorization", "Basic dchZ2VudDM6cGFdGVzC5zc3dvmQ=");
    
28.08.2017 / 17:23