Hi everybody,

I need some help doing a rfc 2617 basic HTTP authentication to call a web service in C#. I've been trying in many ways and I'm really stuck. Here's an example of my current code

string url = "http://somedomain.com/somegenericservice";
			WebRequest myReq = WebRequest.Create(url);

string username="****";
string 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();
			WebService.Service  WebService = new WebService.Service ();

			Uri uri = new Uri(url);
			System.Net.NetworkCredential NC = new System.Net.NetworkCredential("****", "****");
			System.Net.ICredentials IC = NC.GetCredential(uri, "Basic");
			WebService.Credentials = IC;

With this code, I get a Http 500 error (internal error). If I just use the normal network credentials, I get a HTTP 401 error, not authorized.

This is freaking me out a bit. Can anybody give me a hand?

Thanks in advance.


Care to share how?

Did you figure it out? I have to do similar to what you did. Please post if you have figured it out. I appreciate your help.

Thank you,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.