[英]Downloaded files using WebClient.DownloadFile() do not work
So I've been trying to download a file from MediaFire using WebClient.DownloadFile(), but all files I download do not work properly.所以我一直在尝试使用 WebClient.DownloadFile() 从 MediaFire 下载文件,但我下载的所有文件都无法正常工作。 I've tried to download PDF files and PNG files, none of them open correctly in their respective software.
我尝试下载 PDF 文件和 PNG 文件,但它们都无法在各自的软件中正确打开。 I'm using this for a WinForms desktop application.
我将它用于 WinForms 桌面应用程序。 I've already searched for multiple solutions but none of them apply to my situation.
我已经搜索了多种解决方案,但没有一个适用于我的情况。
This is the code I've used:这是我使用的代码:
private void downloadFile(string url, string filename)
{
var client = new WebClient();
client.DownloadFile(url, filename);
}
I'm a begginer so any help is appreciated!我是一个初学者,所以任何帮助表示赞赏!
I found the solution myself with some help from Jimi .我在Jimi 的帮助下自己找到了解决方案。 I needed to find the link the page was using for the download process, not the link to the page itself.
我需要找到页面用于下载过程的链接,而不是页面本身的链接。 I did this by accessing the code of the page using the inspect tool and finding the direct link to the file, then using my previous method it worked just fine.
我通过使用检查工具访问页面代码并找到文件的直接链接来做到这一点,然后使用我以前的方法它工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.