1

I use NetworkCredential class for request authentication in my C# application. It works well until the username and/or password (entered by a user) contains a non-ASCII character (like in the sample below). In that case the Base64 value of request Authorization header contains invalid character(s), causing the authentication process to fail with 401.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(...);
req.Method = "POST";
req.Credentials = new NetworkCredential("José", "password");
using (Stream s = req.GetRequestStream())
{
  byte[] data = new byte[128];
  new Random().NextBytes(data);
  s.Write(data, 0, data.Length);

  HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
  ...
}

When inspecting the request in Fiddler, I see

Authorization: Basic Sm9z6TpwYXNzd29yZA==

which, after decoding, reads

Jos�:password

I came across this issue using .NET Framework 4.0, but the same persists in 4.5 and even 4.8. Is there some way to get this work? I would like to keep using the NetworkCredential class as it handles NTLM and Kerberos authentication automatically.

kibitzerCZ
  • 487
  • 8
  • 20

0 Answers0