Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest not passing Credentials

I'm trying to use HTTPWebRequest to access a REST service, and am having problems passing credentials in, see code below. I've read that NetworkCredential doesn't support SSL, and I'm hitting an HTTPS site. Does anyone know of a class similar to NetworkCredential that does support SSL?

Uri requestUri = null; Uri.TryCreate("https://mywebserver/webpage", UriKind.Absolute, out requestUri); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri); NetworkCredential nc = new NetworkCredential("user", "password"); request.Credentials = nc; request.Method = WebRequestMethods.Http.Get; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
like image 778
Russ Clark Avatar asked Nov 09 '09 17:11

Russ Clark


1 Answers

See if it shows up when you use the old-fashioned method:

string credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("user"+ ":" + "password")); request.Headers.Add("Authorization", "Basic " + credentials); 
like image 177
Ed Power Avatar answered Sep 22 '22 00:09

Ed Power