REST Service - call from ASP.NET 4.0 fails for certain passwords

257 Views Asked by At

I am calling a REST based service API from a ASP.NET 4.0 Webforms application.

The REST service requires HTTP Basic Auth and this has worked just fine so far. I'm using this code snippet to define my credentials for my HttpWebRequest object (serviceUsername, serviceUserPassword and serviceUrl are strings being passed in):

NetworkCredential credentials = new NetworkCredential(serviceUsername, serviceUserPassword);

HttpWebRequest httpReq = WebRequest.Create(serviceUrl) as HttpWebRequest;
httpReq.Credentials = credentials;
httpReq.Method = "GET";
httpReq.Accept = "application/json";

and then I fire off my request.

Today, suddenly, for one customer, things went haywire. Nothing seemed to work anymore - all my calls were rejected with a HTTP 401 - Unauthorized - even though, using the same URL and credentials, I was able to call this REST API from Fiddler.

The ultimate reason was a £ character in the password......

So Fiddler seems to have handled that gracefully, somehow - while ASP.NET falls flat on its nose. What extra step do I need to do in order for ASP.NET 4.0 to also work gracefully even if my customer decides to put a pound symbol in their (probably machine-generated) password? Any tricks or way to handle this?

0

There are 0 best solutions below