Downloading pdf file using WebRequests
Skip the BinaryReader
and BinaryWriter
and just copy the input stream to the output FileStream
. Briefly
var fileName = "output/" + date.ToString("yyyy-MM-dd") + ".pdf";
using (var stream = File.Create(fileName))
resp.GetResponseStream().CopyTo(stream);
Why not use the WebClient
class?
using (WebClient webClient = new WebClient())
{
webClient.DownloadFile("url", "filePath");
}
Your question asks about WebClient
but your code shows you using Raw HTTP Requests & Resposnses.
Why don't you actually use the System.Net.WebClient
?
using(System.Net.WebClient wc = new WebClient())
{
wc.DownloadFile("http://www.site.com/file.pdf", "C:\\Temp\\File.pdf");
}