C#单一 - 错误:SecureChannelFailure - 某些域的HTTPS请求失败
问题描述:
通过阅读关于此问题的所有问题,经过几个小时,我没有别的选择,只能自己发帖。 我有一个非常简单的C#代码从URL返回HTML代码:C#单一 - 错误:SecureChannelFailure - 某些域的HTTPS请求失败
string url = "https://www.google.fr";
var encoding = Encoding.GetEncoding("iso-8859-1");
using (WebClient client = new WebClient())
{
string html = new StreamReader(client.OpenRead(url), encoding).ReadToEnd();
Console.Write(html);
}
在大多数情况下,这个程序返回的结果,除了一些导致异常域:
Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
我尝试了其他问题的一切,但没有人能解决我的问题。我已经尝试重写这样的:
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
来自单的问题,因为它没有在Mono正确在Windows 10 工作,工作的领域我怎样才能避免这种例外?
答
经过几天和几天的搜索解决方案,我明白我必须使用一个技巧,因为错误来自单声道。
这不是正确的方法,但最简单。
我用一个免费域名托管包含这 domain.com/myfile.php
一个PHP文件:
<?php echo file_get_contents("url of the website"); ?>
然后,而不是使用URL导致了问题,我更换PHP文件在C#中的链接。
string url = "domain.com/myfile.php";
using (WebClient client = new WebClient())
{
string html = client.DownloadString(url);
lines = Regex.Split(html, @"\r?\n|\r");
client.Dispose();
}
的[我如何解决与单OSX SecureChannelFailure](可能的复制https://*.com/questions/41827960/how-do-i-resolve-securechannelfailure-on-osx-with-mono ) – SushiHangover
我相信Mono对TLS 1.2的支持仍然有限。我过去也遇到了同样的问题,并且在Mono和URL之间加入了一个代理(我在Node.js中使用了一个轻量级的Web代理,但其他人也会这样做)。最终,您需要一个可以处理TLS的代理服务器,并允许您从单声道的其他设备中调用其他内容。 SSL。 – muszeo