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);
}
SSL Stands for secure sockets layer. Protocol for web browsers and servers that allows for the authentication, encryption and decryption of data sent over the Internet.
I found te solution this blog helped me
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
{
// local dev, just approve all certs
if (development) return true;
return errors == SslPolicyErrors.None ;
};
https://www.khalidabuhakmeh.com/validate-ssl-certificate-with-servicepointmanager
Before use HttpClient you should setup HttpClientHandler;
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback +=
(sender, certificate, chain, errors) =>
{
return true;
};
only than your HttpClient code. Must Work for .net Core 3.*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With