webClient.DownloadFile() return 404
webClient.DownloadFile() return 404
浏览器下载文件 url ok,但是 webClient return 404
string url = "http://zakupki.gov.ru/44fz/filestore/public/1.0/download/priz/file.html?uid=19CC93BEA67C4650B51D69CAA28CB27D";
using (var webClient = new WebClient())
{
webClient.DownloadFile(url , "name");
}
Web 浏览器完成的请求与 WebClient 发出的请求之间存在差异。
您需要将此添加到您的代码中:
webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
因此您的代码将更改为:
string url = "http://zakupki.gov.ru/44fz/filestore/public/1.0/download/priz/file.html?uid=19CC93BEA67C4650B51D69CAA28CB27D";
using (var webClient = new WebClient())
{
webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
webClient.DownloadFile(url, "name.docx");
}
希望对你有帮助
浏览器下载文件 url ok,但是 webClient return 404
string url = "http://zakupki.gov.ru/44fz/filestore/public/1.0/download/priz/file.html?uid=19CC93BEA67C4650B51D69CAA28CB27D";
using (var webClient = new WebClient())
{
webClient.DownloadFile(url , "name");
}
Web 浏览器完成的请求与 WebClient 发出的请求之间存在差异。
您需要将此添加到您的代码中:
webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
因此您的代码将更改为:
string url = "http://zakupki.gov.ru/44fz/filestore/public/1.0/download/priz/file.html?uid=19CC93BEA67C4650B51D69CAA28CB27D";
using (var webClient = new WebClient())
{
webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
webClient.DownloadFile(url, "name.docx");
}
希望对你有帮助