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

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

instead of the actual file content.

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

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

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