Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using the code below I get the following error:
Quote:
"The remote server returned an error: (401) Unauthorized."

This used to work under Windows 7 and VS 2010
Now it doesn't work under Windows 10 VS 2017
C#
NetworkCredential credentials = new NetworkCredential(username, password);

// Create a new WebClient object and set the credentials.
WebClient webClient = new WebClient();
webClient.Credentials = credentials;

String downloadAddress = xxx;

webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

Stream data = webClient.OpenRead(downloadAddress);

I have used both an Anonymous and a specific username and password.

Any help will be greatly appreciated.
Thanks in advance,
Michael

What I have tried:

I have tried multiple things but nothing works.
Posted
Updated 25-Aug-17 14:36pm
v2
Comments
Graeme_Grant 25-Aug-17 20:26pm    
Which remote service are you trying to connect to?
Please click on the "Improve question" widget and update the information in your question.
Richard MacCutchan 26-Aug-17 4:31am    
Probably means that the owners of that website do not allow downloading of their files.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900