As I am not getting any help on the offical nanoFrameowork github page I thought maybe somebody here could help.
So I am using the nanoFramework on an ESP32 device and I am trying to send a webrequest to a server on my network, but I'm getting the following:
++++ Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ++++ ++++ Message: ++++ System.Net.Security.SslNative::SecureConnect [IP: 0000] ++++ ++++ System.Net.Security.SslStream::Authenticate [IP: 0054] ++++ ++++ System.Net.Security.SslStream::AuthenticateAsClient [IP: 000a] ++++ ++++ System.Net.HttpWebRequest::EstablishConnection [IP: 027c] ++++ ++++ System.Net.HttpWebRequest::SubmitRequest [IP: 001a] ++++ ++++ System.Net.HttpWebRequest::GetRequestStream [IP: 0008] ++++ ++++ System.Net.Http.HttpMessageInvoker::Send [IP: 0013] ++++ ++++ System.Net.Http.HttpClient::Send [IP: 006f] ++++ ++++ System.Net.Http.HttpClient::Post [IP: 0011] ++++
My code:
private const string myCACertificate = @"-----BEGIN CERTIFICATE----- text of my cert removed for brevity -----END CERTIFICATE-----";
private static HttpClient _httpClient = new HttpClient()
{
HttpsAuthentCert = new X509Certificate(myCACertificate),
SslProtocols = System.Net.Security.SslProtocols.Tls12
};
string json = JsonConvert.SerializeObject(new MyObject());
StringContent strcontent = new StringContent(json, Encoding.UTF8, "application/json");
string url = $"https://myserver:8788/api/path";
var response = _httpClient.Post(url, strcontent);
The nanoframework is obviously more limited compared to 'full' .net.
It seems to be some kind of certificate issue with SSL, but I can't find any more details or better examples online, so don't really know why this doesn't work and what I need to do to get this working.