httpclient cannot access the api of incus

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 = "";
            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
| incus-uiserver.crt | client | | 97ef3368b0d4 | 2027/01/11 20:17 CST |

This problem has been bothering me for two days. God please help me.

I am new to incus, I hope someone can help me.

Can you try with curl first to make sure things properly at the API level?

curl --cert /path/to/file.crt --key /path/to/file.key -k
root@debian:/home# curl --cert /home/server2.crt --key /home/server2.key -k

This verification is normal and there is no problem

Okay, so then the issue is in your code which isn’t in a language I’m familiar with so you’re going to have to do more digging and debugging there :slight_smile:

okay,thank you