1

After hours by reading all questions about this issue, i have no other choice than posting by myself. I have a very simple C# code which return html code from URL :

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);
}

In most of case, this program return a result, except for some domains that causes an exception :

 Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.

I tried everything from other issues, but no one can solve my problem. I have already tried to override like this :

 ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

The problem come from Mono, because the domains which doesn't work on Mono, work properly on Windows 10. How can I avoid this exception ?

Okn
  • 698
  • 10
  • 21
  • Possible duplicate of [How do I resolve SecureChannelFailure on OSX with mono](https://stackoverflow.com/questions/41827960/how-do-i-resolve-securechannelfailure-on-osx-with-mono) – SushiHangover Jul 03 '17 at 06:25
  • Support for TLS 1.2 is still limited in Mono I believe. I've had the same issue in the past and worked around it by putting a proxy in between Mono and the URL (I used a light web proxy in Node.js but others would do the trick just as well). Ultimately you need a proxy that can handle the TLS for you and allow you to call in over something else from mono e.g. SSL. – muszeo Jul 06 '17 at 05:56

1 Answers1

0

After days and days by searching solution, I understand that I had to use a trick because the error come from Mono.

This is not the proper way, but the most simple.

I used a free domain for hosting a php file which contain this in domain.com/myfile.php :

<?php echo file_get_contents("url of the website"); ?>

And then, instead of using the url causing the issue, I replace with the link of PHP file in 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();
}
Okn
  • 698
  • 10
  • 21