X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FSystem.Net%2FBasicClient.cs;h=5d89b269ff3fa143d72af4f78f415fd67d00cfae;hb=3c717f5efc3146217f1b0b3944e38d2b376e8483;hp=d81f944bf1211a7d8867ee21ab052e37c589d942;hpb=0abc2e6270020edc4a5b4c66f93b4ae582815f20;p=mono.git diff --git a/mcs/class/System/System.Net/BasicClient.cs b/mcs/class/System/System.Net/BasicClient.cs index d81f944bf12..5d89b269ff3 100644 --- a/mcs/class/System/System.Net/BasicClient.cs +++ b/mcs/class/System/System.Net/BasicClient.cs @@ -45,13 +45,26 @@ namespace System.Net return InternalAuthenticate (webRequest, credentials); } + static byte [] GetBytes (string str) + { + int i = str.Length; + byte [] result = new byte [i]; + for (--i; i >= 0; i--) + result [i] = (byte) str [i]; + + return result; + } + static Authorization InternalAuthenticate (WebRequest webRequest, ICredentials credentials) { HttpWebRequest request = webRequest as HttpWebRequest; - if (request == null) + if (request == null || credentials == null) return null; NetworkCredential cred = credentials.GetCredential (request.AuthUri, "basic"); + if (cred == null) + return null; + string userName = cred.UserName; if (userName == null || userName == "") return null; @@ -62,9 +75,9 @@ namespace System.Net // If domain is set, MS sends "domain\user:password". if (domain == null || domain == "" || domain.Trim () == "") - bytes = Encoding.Default.GetBytes (userName + ":" + password); + bytes = GetBytes (userName + ":" + password); else - bytes = Encoding.Default.GetBytes (domain + "\\" + userName + ":" + password); + bytes = GetBytes (domain + "\\" + userName + ":" + password); string auth = "Basic " + Convert.ToBase64String (bytes); return new Authorization (auth);