Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a government network, where all users are logged in via a CAC card. I want to download a file from a secure web site which uses my CAC credentials to allow access.

I've tried using WebClient, and then HttpWebRequest/HttpWebResponse to download the file, but it ain't workin'.

What do I have to do to download the file directly using c#?
Posted

I found out what to do. Simply set the property HttpWebRequest.UseDefaultCredentials to true.
 
Share this answer
 
Hi John, can you please try with the below code.
C#
var httpRequest = (HttpWebRequest)WebRequest.Create(@"https://yoursite/fileToDownload.ext");
         httpRequest.Credentials = new NetworkCredential("username", "password", "domainname");
         var httpResponse = (HttpWebResponse)httpRequest.GetResponse();

         var downloadStrm = httpResponse.GetResponseStream();
         var donloadStrm = new StreamReader(downloadStrm);
         // Do whatever you want with donloadStrm
         downloadStrm.Close();
 
Share this answer
 
Comments
#realJSOP 15-Oct-14 11:40am    
I already solved the problem. Read the first soltuion.
NaibedyaKar 15-Oct-14 11:44am    
Ahh, ok. Good.

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