Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebClient generates (401) Unauthorized error

I have the following code running in a windows service:

WebClient webClient = new WebClient(); webClient.Credentials = new NetworkCredential("me", "12345", "evilcorp.com"); webClient.DownloadFile(downloadUrl, filePath); 

Each time, I get the following exception

{"The remote server returned an error: (401) Unauthorized."} 

With the following inner exception:

{"The function requested is not supported"} 

I know for sure the credentials are valid, in fact, if I go to downloadUrl in my web browser and put in my credentials as evilcorp.com\me with password 12345, it downloads fine.

What is weird though is that if I specify my credentials as [email protected] with 12345, it appears to fail.

Is there a way to format credentials?

like image 335
Matt Avatar asked Jan 27 '10 20:01

Matt


People also ask

Why do I get 401 unauthorized?

The 401 Unauthorized error is an HTTP status code that means the page you were trying to access cannot be loaded until you first log in with a valid user ID and password. If you've just logged in and received the 401 Unauthorized error, it means that the credentials you entered were invalid for some reason.

What is 401 error in REST API?

If you attempt to use an expired token, you'll receive a "401 Unauthorized HTTP" response. When this happens, you'll need to refresh the access token. You shouldn't request a new token for every API call made, as each token is good for an hour and should be reused.

How do I fix 401 unauthorized error on Iphone?

Clear your browser cache and cookies The “HTTP Error 401” is one of the possible results. Clearing your browser cache and cookies is recommended for troubleshooting the “401 Unauthorized” error as well as for most of the errors you encounter.


1 Answers

webClient.UseDefaultCredentials = true; resolved my issue.

like image 132
P.Brian.Mackey Avatar answered Sep 20 '22 16:09

P.Brian.Mackey