W
williamxifaras
I am trying to download a file from a secure web-site. However what is
getting downloaded is just the page html and not the actual file which
happens to be an xml file. Here is my code. Any suggestions would be
most appreciated. I changed the url for security reasons.
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("https://somesite.com/reports/test.xml");
request.Credentials = new NetworkCredential("xxxx",
"xxxx");
request.UserAgent = "Mozilla/4.0+";
request.Accept = "*/*";
request.Headers.Add("Cache-Control", "no-cache");//
force no-caching
request.Method = "GET";
// Downloads the XML file from the specified server.
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
byte[] inBuffer = ReadFully(stream, 32768);
string destFileName =
ConfigurationManager.AppSettings["Directory"].ToString() +
ConfigurationManager.AppSettings["FtpIn"].ToString() + nasdfile;
fstream = new FileStream(destFileName,
FileMode.OpenOrCreate, FileAccess.Write);
fstream.Write(inBuffer, 0, inBuffer.Length);
getting downloaded is just the page html and not the actual file which
happens to be an xml file. Here is my code. Any suggestions would be
most appreciated. I changed the url for security reasons.
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("https://somesite.com/reports/test.xml");
request.Credentials = new NetworkCredential("xxxx",
"xxxx");
request.UserAgent = "Mozilla/4.0+";
request.Accept = "*/*";
request.Headers.Add("Cache-Control", "no-cache");//
force no-caching
request.Method = "GET";
// Downloads the XML file from the specified server.
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
byte[] inBuffer = ReadFully(stream, 32768);
string destFileName =
ConfigurationManager.AppSettings["Directory"].ToString() +
ConfigurationManager.AppSettings["FtpIn"].ToString() + nasdfile;
fstream = new FileStream(destFileName,
FileMode.OpenOrCreate, FileAccess.Write);
fstream.Write(inBuffer, 0, inBuffer.Length);