How to fix "The SSL connection could not be established, see inner exception." when trying to download osu! avatar

Pal*_*veR 5 .net c# ssl avatar

I want to download osu! avatars to use them, but keep getting this error:

The SSL connection could not be established.

Inner exception is:

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> System.ComponentModel.Win32Exception: ???????? ?????????????? ????????? ??? ??? ????? ???????????? ??????

Example url: https://a.ppy.sh/10638551?1524507784.png

I tried using HttpClient and WebClient but without any success.

using(HttpClient client = new HttpClient())
{
     var resp = await client.GetAsync("https://a.ppy.sh/10638551?1547998515.jpeg");
     var responseStr = await resp.Content.ReadAsStringAsync();
     File.WriteAllText("html/avatars/avatar.jpeg", responseStr);
}
Run Code Online (Sandbox Code Playgroud)

小智 6

我找到了这个博客帮助我的解决方案

ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
{
    // local dev, just approve all certs
    if (development) return true;
    return errors == SslPolicyErrors.None ;
};
Run Code Online (Sandbox Code Playgroud)

https://www.khalidabuhakmeh.com/validate-ssl-certificate-with-servicepointmanager

  • 小心,这种代码在您意识到之前就会泄漏到生产环境中 (6认同)

Pal*_*veR -2

回答:


一段时间后,我发现我使用的库有点糟糕。之后我发现了硒。

考虑到这一点,我开始使用 Selenium WebDriver 并认为我可以截取我需要的页面的屏幕截图,然后我裁剪该图像并得到我需要的内容。
所以这个问题就没有必要再继续下去了。

  • 使用这种方法并不能解决问题。 (6认同)