1

我在 Mac 上使用 Mono 3 玩 Runscope。使用下面的代码我得到一个异常:

System.Net.WebException: Error getting response stream (Write: The authentication or decryption has failed.): SendFailure ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.

我不明白为什么,因为ServicePointManager.ServerCertificateValidationCallback应该有效地批准所有证书。

另请注意,该代码在 Windows 上的 Visual Studio 下完美运行。

有任何想法吗?

class Program
    {
        private static Uri url = new Uri("https://api-github-com-[MY_PERSONAL_TOKEN_HERE].runscope.net/");

        static void Main(string[] args)
        {
            ServicePointManager.ServerCertificateValidationCallback +=
                (sender, cert, chain, sslPolicyErrors) => true;
            MakeRequest();
            Console.ReadKey ();
        }

        private static async Task MakeRequest()
        {
            try
            {
            var httpClient = new HttpClient();
            var response = await httpClient.GetAsync(url);
            var body = await response.Content.ReadAsStringAsync();
            Console.WriteLine("Body: " + body);
            }
            catch(Exception ex)
            {
                Console.WriteLine (ex);
            }
        }
    }
4

0 回答 0