gpt4 book ai didi

ssl - IIS、TLS 和 SSL 版本或 C# 中的 SSL HttpWebRequest“无法创建 SSL/TLS 安全通道

转载 作者:太空宇宙 更新时间:2023-11-03 14:50:01 25 4
gpt4 key购买 nike

有几件事,另一个服务器(Webmethods Integration Server)对它接受的协议(protocol)类型有点挑剔。因此,经过这里的一些摆弄是修复它的两件事:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

req.ProtocolVersion = HttpVersion.Version10;

所以整个代码是:

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

**//for TLS Version as set TLSv1.2**

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://websiteURL:9000");

//Header Settings

req.Method = "POST"; // Post method

req.ContentType = "text/xml";// content type

req.KeepAlive = false;

req.ProtocolVersion = HttpVersion.Version10;

//Certificate with private key

X509Certificate2 cert = new X509Certificate2("Cert.der","Password");

req.ClientCertificates.Add(cert);

req.PreAuthenticate = true;

String XML = "Test Message"//reader.ReadToEnd();

byte[] buffer = Encoding.ASCII.GetBytes(XML);

req.ContentLength = buffer.Length;

// Wrap the request stream with a text-based writer

Stream writer = req.GetRequestStream();

// Write the XML text into the stream

writer.Write(buffer, 0, buffer.Length);

writer.Close();

WebResponse rsp = req.GetResponse();

StreamReader responseStream = new StreamReader(rsp.GetResponseStream());

最佳答案

//对于 TLS 版本,在服务调用之前设置 TLSv1.2 调用

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

关于ssl - IIS、TLS 和 SSL 版本或 C# 中的 SSL HttpWebRequest“无法创建 SSL/TLS 安全通道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35316902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com