最近公司要对接电信物联网北向API接口,当调用Auth授权接口时,需要用到证书,此篇文章记录下遇到的坑~
有两种调用接口的方式,下面是两种方式的简单示例
1、使用
HttpClient
public static void Post(string appId, string secret)
{
var handler = new HttpClientHandler
{
ClientCertificateOptions = ClientCertificateOption.Manual,
SslProtocols = SslProtocols.Tls12,
ServerCertificateCustomValidationCallback = (x, y, z, m) => true,
};
var path = Path.Combine(AppContext.BaseDirectory, "cert\\iot3rd.p12");
handler.ClientCertificates.Add(new X509Certificate2(path, "IoM@1234"));
var client = new HttpClient(handler);
var content = new StringContent($"appId={appId}&secret={secret}");
content.Headers.ContentType = new MediaTypeHeaderValue