带证书的post请求---HttpClient


 public static string HttpPostCert(string uri, string jsontxt)
        {
            var handler = new HttpClientHandler();
            handler.ClientCertificateOptions = ClientCertificateOption.Manual;
            handler.SslProtocols = SslProtocols.Tls12;
            handler.ClientCertificates.Add(new X509Certificate2("证书地址跟密码地址"));
            var retData = string.Empty;
            using (var httpClient = new HttpClient())
            {
                var content = new StringContent(jsontxt);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = httpClient.PostAsync(ServiceDomain + uri, content).Result;
                retData = response.Content.ReadAsStringAsync().Result;
            }
            return retData;
        }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM