How can I use the Webrequest Credentials
Property to send an basic authentication header?
Why isn't the Authorization header send with the request even whenPreAuthenticate
is set to true?
WebRequest request = (HttpWebRequest)WebRequest.Create("https://api.github.com/user");
request.Credentials = new NetworkCredential("githubUsername", "githubPassword");
request.PreAuthenticate = true;
var response = request.GetResponse();
See Question&Answers more detail:os