httpclient cannot access the api of incus. The client trust certificate has been added to the server. The code is as follows
public IActionResult ChangeVm()
{
string zs = @"H:\projet\2019test\testrunstr\strrunapi\bin\Debug\net5.0\incus-ui.pfx";
var handler = new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Default
};
handler.ClientCertificates.Add(new X509Certificate2(zs, "123",X509KeyStorageFlags.UserKeySet));
using (var http=new HttpClient(handler))
{
var val = new { action = "stop"};
StringContent sc = new StringContent(JsonConvert.SerializeObject(val));
sc.Headers.ContentType = new MediaTypeHeaderValue("application/json");
string path = "https://192.168.193.183:8443/1.0/instances/test/state?project=default";
var str = http.PutAsync(path, sc).Result.Content;
return Json(str);
}
}
Certificates trusted by the server have been added
root@debian:~# incus config trust list
±-------------------±-------±------------±-------------±---------------------+
| NAME | TYPE | DESCRIPTION | FINGERPRINT | EXPIRY DATE |
±-------------------±-------±------------±-------------±---------------------+
| incus-uiserver.crt | client | | 97ef3368b0d4 | 2027/01/11 20:17 CST |
±-------------------±-------±------------±-------------±---------------------+
This problem has been bothering me for two days. God please help me.