Click here to Skip to main content
15,563,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I used following code to download file from secured site but file created on folder @"C:\Downloads\Filename" show HTML tags like this

HTML
<HTML>
<HEAD><LINK rel="stylesheet" type="text/css" name="defaultstyle" href="/cehttp/html/style.css">
<TITLE>Servlet Response Message</TITLE></HEAD>
<BODY>
<H2 align=center><H2>
<HR>
You are not logged on. Please logon first.
<HR>
</BODY></HTML>


instead of the actual file content.

C#
try
       {
           WebClient client = new WebClient();
           client.Credentials = new System.Net.NetworkCredential("username", "password");
           byte[] pageData = client.DownloadData("url");
           string pageHtml = Encoding.ASCII.GetString(pageData);
           Console.WriteLine(pageHtml);

           client.DownloadFile("url", @"C:\Downloads\071213.ACCT");
       }
       catch (WebException webEx)
       {
           Console.WriteLine(webEx.ToString());
           if (webEx.Status == WebExceptionStatus.ConnectFailure)
           {
               Console.WriteLine("Are you behind a firewall?  If so, go through the proxy server.");
           }
       }
Posted
Updated 14-Jul-13 23:17pm
v4

1 solution

That's some mechanism on the server side: they check somehow that you are logged in, and your username ans password are not enough. I can only guess that they might use cookies, check referers, check session variables,...
 
Share this answer
 

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