Hi All, 

Can anyone tell me the difference? 

Scenario: 

I have an aspx page on my computer that runs IIS. It uses SSL and MS 
Basic Authentication scheme for authentication/authorization. 

Below are two ways my webclient is written (using httpwebrequest): 

1) ..... 

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create
(m_uri); 

string cred = String.Format("{0}:{1}", "username", "password"); 

byte [] bytes = System.Text.Encoding.ASCII.GetBytes(cred); 

string base64 = Convert.ToBase64String(bytes); 

httpRequest.Headers.Add("Authorization", "Basic " + base64); 

HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse
(); 

2)..... 

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create
(m_uri); 

NetworkCredential cred=new NetworkCredential("username","password");
 
httpRequest.Credentials = cred; 

HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse
(); 

Firstly, solution (2) works while solution (1) doesnt. I get 
an "Unauthorized" error with solution (1). Aren't they the same? I'm 
assuming the "Network Credentials" class in solution (2) hides all 
the nitty-gritty details of solution (1). Am i right?





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/Microsofts_C_Sharp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to