[ACCEPTED]-401 Unauthorized returned on GET request (https) with correct credentials-httpwebrequest
Accepted answer
Try this:
var uri = new Uri("https:/example.com/auth");
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Accept = "application/xml";
// authentication
var cache = new CredentialCache();
cache.Add(uri, "Basic", new NetworkCredential("user", "secret"));
request.Credentials = cache;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
// response.
var response = (HttpWebResponse)request.GetResponse();
Note the use of the NetworkCredential
class instead 1 of rolling your own authentication headers.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.