.NET WebRequest class does not base64 encode the Authorization header when using HTTP basic Auth. This leads to failing authentication, if your credentials contain special characters like an email address(as username) does.
So in case you are lost you might try this code:
[cc lang=“csharp“]
WebRequest myReq = WebRequest.Create(url);
string username=“username“;
string password=“password“;
string usernamePassword = username + „:“ + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), „Basic“, new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add(„Authorization“, „Basic “ + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
[/cc]
I am not a .NET programmer and found this after a 4 hour support session with a customer. So if you have got something to amend please comment.