I'm trying to communicate with a backend server using SSL. I'm trying using HttpClient from the System.Net.Http library, but I couldn't get it working. This is my code (Debug.Log is just a print since I'm using Unity):
public static async Task DownloadPageAsync(string web)
{
try
{
HttpClient cl = new HttpClient();
string body = await cl.GetStringAsync(new Uri(web));
Debug.Log(web);
}
catch (HttpRequestException e)
{
Debug.Log(e.InnerException.Message);
}
catch (Exception ex)
{
Debug.Log(ex.ToString());
}
}
When I try it in a web with a bad certificate, it gives: "Error: TrustFailure (The authentication or decryption has failed.)", which is fine. The problem is that good certificates also triggers an error: "Error: SecureChannelFailure (The authentication or decryption has failed.)".
I've saw other answers saying that simply accepting all the certificates works fine, but I need to check if it's a valid certificate or not.
¿Is there a way of doing it with HttpClient? ¿Or with some other class?
Btw, I'm only using it to send POST request, and receiving a simple string.
Thank you!