2017-07-02 51 views
1

通過閱讀關於此問題的所有問題,經過幾個小時,我沒有別的選擇,只能自己發帖。 我有一個非常簡單的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 工作,工作的領域我怎樣才能避免這種例外?

+0

的[我如何解決與單OSX SecureChannelFailure](可能的複製https://stackoverflow.com/questions/41827960/how-do-i-resolve-securechannelfailure-on-osx-with-mono ) – SushiHangover

+0

我相信Mono對TLS 1.2的支持仍然有限。我過去也遇到了同樣的問題,並且在Mono和URL之間加入了一個代理(我在Node.js中使用了一個輕量級的Web代理,但其他人也會這樣做)。最終,您需要一個可以處理TLS的代理服務器,並允許您從單聲道的其他設備中調用其他內容。 SSL。 – muszeo

回答

0

經過幾天和幾天的搜索解決方案,我明白我必須使用一個技巧,因爲錯誤來自單聲道。

這不是正確的方法,但最簡單。

我用一個免費域名託管包含這 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(); 
} 
相關問題