浏览器使用此url下载文件可以,但webClient返回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");
}发布于 2018-08-21 00:40:58
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");
}我希望它能帮助你
https://stackoverflow.com/questions/51934863
复制相似问题