Click here to Skip to main content
15,220,579 members
Rate this:
Please Sign up or sign in to vote.
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>
<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.

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 22:17pm
v4

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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,...
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100