请求被中止了,无法创建 SSL/TLS 安全通道 webClient C#。

3

大家好,我在WebClient中遇到了一个问题。我的问题是使用WebClient.downloadFile或WebClient.DownloadFileAsync无法下载特定文件,出现错误信息[请求被中止:无法创建SSL / TLS安全通道],而且下载的文件大小为0字节,请帮助我提供任何可下载文件的代码或解决方案。我的代码如下:

WebClient Client = new WebClient();
Client.DownloadFile("https://github.com/MohammedZr/roepo/blob/master/x82bit/32bit.exe", @"C:\Users\MohamedAlzurghni\Desktop\Project\bolo\test\32bit.exe");
2个回答

6

将安全协议设置为Tls12

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
WebClient Client = new WebClient();
Client.DownloadFile("https://github.com/MohammedZr/roepo/blob/master/x82bit/32bit.exe", @"C:\Users\MohamedAlzurghni\Desktop\Project\bolo\test\32bit.exe");

0
根据错误提示,连接未在TLS上建立。
WebClient Client = new WebClient();
Client.DownloadFile(new Uri("https://github.com/MohammedZr/enchantress/blob/master/x82bit/xmrig.exe"), @"C:\Users\MohamedAlzurghni\Desktop\Project\bolo\test\32bit.exe");

您需要设置服务点使用的安全协议。


这意味着该路径下不存在任何文件。您确认吗? - Anish K
好的,也许我应该把GitHub存储库中的URL粘贴在这里,就像这样,我打开了文件路径并打开了它[https://github.com/MohammedZr/roepo/blob/master/x82bit/32bit.exe],那么这就是URL? - MrObscure
点击那个URL链接,会显示页面未找到。 - Anish K
这是一个新的URL,我可以从这个链接下载文件吗!? https://github.com/MohammedZr/enchantress/blob/master/x82bit/xmrig.exe - MrObscure
1
我已经解决了问题,问题出在头文件中。我添加了这个头文件C# Client.Headers.Add("user-agent", "Mozilla"); - MrObscure
显示剩余11条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接