Download file and cookie
<p>I was download text file from protected site (<a href="http://stooq.pl/db/" rel="nofollow">http://stooq.pl/db/</a>), but at the top of the file I get this:</p>

<p>Top of the file:</p>

<blockquote>
  <p><br /> <b>Warning</b>:  mysql_fetch_row(): supplied argument is not a
  valid MySQL result resource in <b>/home/stooq/www/db/d/index.htm</b>
  on line <b>30</b><br /> <br /> <b>Warning</b>:  Cannot modify header
  information - headers already sent by (output started at
  /home/stooq/www/db/d/index.htm:30) in
  <b>/home/stooq/www/db/d/index.htm</b> on line <b>80</b><br /></p>
</blockquote>

<p>Other part of the file (it is OK):</p>

<blockquote>
  <p>^AEX,D,20120906,329.56,336.43,329,336.43,0,0
  ^AOR,D,20120906,4303.8,4343.3,4297.7,4331.64,1387224960,0
  ^ATH,D,20120906,676.01,682.97,667.73,678.96,32649480,0</p>
</blockquote>

<p>Can You help me with this "Warning...".</p>

<p>I use this code for that:</p>

<pre><code>    string loginUrl = "http://www.stooq.pl/q/d/";
    string downloadUrl = "http://stooq.pl/db/d/?d=20120907&amp;t=d";

    FileStream stream = null;
    while (true)
    {
        try
        {
            stream = File.Create(@"C:\20120907_d.prn");
            break;
        }
        catch { }
    }

    // Assuming the webapp uses cookies!
    HttpWebRequest loginRequest =
    (HttpWebRequest)WebRequest.Create(loginUrl);
    loginRequest.CookieContainer = new CookieContainer();
    HttpWebResponse loginResponse =(HttpWebResponse)loginRequest.GetResponse();
    // Get the session id and other cookies set by the web app
    CookieCollection cookies = loginResponse.Cookies;

    HttpWebRequest downloadRequest = (HttpWebRequest)WebRequest.Create(downloadUrl);
    // Make sure to send the cookie(s) back to the webapp.
    downloadRequest.CookieContainer = new CookieContainer();
    downloadRequest.CookieContainer.Add(cookies);
    // Add post data that makes webapp download the file
    HttpWebResponse downloadResponse =(HttpWebResponse)downloadRequest.GetResponse();
    // Stream response bytes to a buffer or file.

    StreamReader reader = new StreamReader(downloadResponse.GetResponseStream());
    string responsestring = reader.ReadToEnd();
    using (StreamWriter sw = new StreamWriter(stream))
    {
        sw.Write(responsestring);
        sw.Close(); 
    }
    reader.Close();
</code></pre>
