在阅读了关于这个问题的所有问题几个小时后,我别无选择,只能自己发帖。我有一个非常简单的C#代码,从网址返回html代码:
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,因为在Mono上不工作的域名在Windows10上可以正常工作。我如何避免这个异常?
发布于 2017-07-16 22:21:53
经过一天又一天的寻找解决方案,我明白我必须使用一个技巧,因为错误来自Mono。
这不是正确的方法,而是最简单的方法。
我使用了一个免费的域名来托管一个php文件,该文件在domain.com/myfile.php中包含以下内容:
<?php echo file_get_contents("url of the website"); ?>然后,我没有使用导致问题的url,而是将其替换为C#中的PHP文件的链接。
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();
}https://stackoverflow.com/questions/44876171
复制相似问题