WebClient.DownloadFile creates an error ??

C

Chris

Hi,

I try to download a file using the following :

WebClient client = new WebClient();
client.Credentials = new NetworkCredential("Administrator",
"test","MYPC");
client.DownloadFile("http://localhost/afile.txt", "c:\\test.txt");

but I get an error :
The remote server returned an error: (403) Forbidden.

how come ?

thanks
Chris

(I'm executing everything on my machine where I'm logged in as
'Administrator')
 
C

Chris

Hi Patrice,

actually I just want to download a file for which I have the url. (The file
is not visualized nowhere in the browser)

what are the possibilities ?

thanks
Chris
 
P

Patrice

I unsderstood. Just wanted to know it it works manually especially with this
exact credentials.

Check also my other post (did you omitted the code that uses the credentials
or is this code missing from your code ?)

--
 
C

Chris

Without the credential-code ...
client.Credentials = new NetworkCredential("Administrator",
"nav01ils","PC-
WIN2000");

.... do I get the error
The remote server returned an error: (401) Unauthorized

With the credential-code do I get the error
The remote server returned an error: (403) Forbidden.
 
P

Patrice

And are you able to access this file when using a browser and entering
manually these credentials ? This is to find out if the problem is rather in
the code or if there is something wrong regarding the security settings.

Also the code I saw uses generally a CredentialCache. In particular it
allows to specify the authentication method to use. I believe it could miss
from your code :
(taken from the doc) :

CredentialCache myCache = new CredentialCache();

myCache.Add(new Uri("http://www.contoso.com/"),"Basic",new
NetworkCredential(UserName,SecurelyStoredPassword));
myCache.Add(new Uri("http://www.contoso.com/"),"Digest", new
NetworkCredential(UserName,SecurelyStoredPassword,Domain));

wReq.Credentials = myCache;

See :
http://msdn.microsoft.com/library/d...rlrfsystemnetcredentialcacheclassaddtopic.asp
for details...

So I would check first :
- security is ok, I can access the ressource manually with these exact same
credentials
- then I would try to use a credential cache to specifiy the URI as well as
the authentication method used
- if it wokrs I woukld then, eventually try to use directly the Credentials
(I'm really not sure what the .NET library does when these informations
can't be found from the CredentialCache).

Patrice
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top