How can I add Headers to an Httpwebrequest

Asked

Viewed 579 times

0

I am wearing

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

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

  • What kind of training, be very specific.?

1 answer

4


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=");
  • That way it didn’t work on my show .

  • ta using Httpclient?

  • I am using Httpwebrequest

  • update it to webrequest see if you can do this

  • Thank you very much just wait two more minutes to accept the answer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.