Tuesday, April 24, 2007

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();

9/22/2007 11:21:11 PM (Mitteleuropäische Sommerzeit , UTC+02:00)
Hi! Nice topic!
12/3/2007 2:14:59 AM (Mitteleuropäische Zeit , UTC+01:00)
This is great! One question: Is there any way around the authentication issue? I have a portal which requires a login/password. Am I out of luck?
11/16/2009 12:29:15 PM (Mitteleuropäische Zeit , UTC+01:00)
Thanks for this. I had been banging my head on a brick wall over this. Even Yahoo have an example which doesn't work and I guess it's something to do with the request not allow plain text over http.
11/25/2009 6:57:11 AM (Mitteleuropäische Zeit , UTC+01:00)
Thanks for sharing this post .That's very interesting.
5/10/2010 10:14:08 PM (Mitteleuropäische Sommerzeit , UTC+02:00)
This really helped ! Finally ... Thanks !
Dusan
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):