带有自定义rootCA证书以及客户端证书和客户端密钥的http发布

时间:2018-09-08 07:40:59

标签: c# .net-core certificate

我正在尝试通过AWS-iot上的http post发布mqtt消息。 对于某些原因,我想使用.net core和http发布。

发布时,它要求使用自定义rootCA证书和客户端证书以及客户端私钥(https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html

下面是仅适用于客户端证书的代码

HttpClientHandler handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
handler.ClientCertificates.Add(new X509Certificate2("client.crt"));

HttpClient http = new HttpClient(handler);
var post_content = new StringContent("", System.Text.Encoding.UTF8, "application/json");
var response = http.PostAsync(mqtt_endpoint, post_content);
var res_content = response.Result.Content.ReadAsStringAsync().Result;

0 个答案:

没有答案