如何通过https发送证书

时间:2019-06-14 08:28:15

标签: c# ssl httpclient tls1.2

我正在尝试使用证书连接到服务器。哪个给了我。

此cURL命令有效,我正在尝试用C#来实现。

curl.exe -vvv --cert client.crt --key client.key --header -X POST "https://foobar.com:7777" --data "TERMINAL_ID=130574061&GAME_ID=7105&DRAW_ID=1200"

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            X509Certificate2 cert = new X509Certificate2("client.crt", "PASSWORD");

            WebRequestHandler clientHandler = new WebRequestHandler
            {
                Credentials = CredentialCache.DefaultCredentials,
                AllowAutoRedirect = false,
                PreAuthenticate = true,
                ClientCertificateOptions = ClientCertificateOption.Manual,
                //SslProtocols = SslProtocols.Tls12,
                CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore),
                //ServerCertificateCustomValidationCallback = delegate { return true; },
            };


            clientHandler.ClientCertificates.Add(cert);
            var content = new StringContent(PathData.Data);

            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            using (HttpClient client = new HttpClient(clientHandler))
            {
                client.BaseAddress = new Uri(PathData.ShortUri);
                var response = await client.PostAsync("/fprov/fcgi_gameprops?id=30", content);
            }

当我执行PostAsync时,出现错误“ WebException:请求被中断:无法创建安全的SSL / TLS通道。”

0 个答案:

没有答案