I have used this code other places with no problem. The site I'm trying to download from now is always coming back as corrupt. Is there something else I need to add to this code to successfully bring this file down to my machine? Here's my code.
string strVars = "";
try
{
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format("{0}{1}", strPage, strVars));
string[] h;
if (headers.Length > 0)
{
h = headers.Split(Convert.ToChar(","));
foreach (string s in h)
{
WebReq.Headers.Add(s);
}
}
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
StreamWriter sw = new StreamWriter(fileName,false);
sw.WriteLine(_Answer.ReadToEnd());
sw.Close();
string strVars = "";
try
{
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format("{0}{1}", strPage, strVars));
string[] h;
if (headers.Length > 0)
{
h = headers.Split(Convert.ToChar(","));
foreach (string s in h)
{
WebReq.Headers.Add(s);
}
}
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
StreamWriter sw = new StreamWriter(fileName,false);
sw.WriteLine(_Answer.ReadToEnd());
sw.Close();