我通常使用以下代码下载文件:
My.Computer.Network.DownloadFile("url of the file","filepath to save the file")
Run Code Online (Sandbox Code Playgroud)
但是最近我遇到了一个网站,如果你从它的网站点击它而不是直接从vb.net代码下载,它只允许文件下载.
我的问题是:如何在允许下载之前从需要引用的http服务器下载文件?
尝试手动添加Referer标头:
WebClient wc = new WebClient();
wc.Headers.Add("Referer","http://whatever.com");
wc.DownloadFile("url of the file","filepath to save the file");
Run Code Online (Sandbox Code Playgroud)