[英]Could not create SSL/TLS secure channel with HttpRequest
Hi I am trying to do a HttpRequest to a website and when I call GetRequestStream()
I keep getting this Error. 嗨,我正在尝试对网站进行HttpRequest,当我调用
GetRequestStream()
我一直收到此错误。
My code: 我的代码:
byte[] data = Encoding.ASCII.GetBytes(myJson);
// Create a request for the URL.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"https://host-address.com:443");
request.ServerCertificateValidationCallback += (sender, certificate2, chain, sslPolicyErrors) => {
return true;
};
X509Certificate2Collection certificates = new X509Certificate2Collection();
certificates.Import("C:\\Certs\\MyCertificate.pfx", "myCertPassword", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
request.ClientCertificates = certificates;
request.Method = "POST";
request.ContentType = "text/json";
request.ContentLength = data.Length;
request.UserAgent = "My User Agent";
request.ProtocolVersion = HttpVersion.Version11;
request.KeepAlive = true;
Console.WriteLine("Requesting connection....");
//The exception is thrown here
using (Stream stream = request.GetRequestStream()) //Here's where the exception happens
{
stream.Write(data, 0, data.Length);
}
I already tried this Could not create SSL/TLS secure channel, despite setting ServerCertificateValidationCallback but not seems to work, also set the delegate ServerCertificateValidationCallback
to always return true but it's not even reaching that part. 尽管设置了ServerCertificateValidationCallback但似乎无法正常工作,但我已经尝试过此“ 无法创建SSL / TLS安全通道”,还将委托
ServerCertificateValidationCallback
设置为始终返回true,但甚至没有达到该值。
This might be a cypher problem? 这可能是密码问题吗? Due that I can get a response from the page when I browse it on chrome but not with IE.
因此,当我在chrome上浏览网页时(但无法在IE中浏览),我可以从该网页获得响应。
I would recommend following: 我建议以下内容:
Hope this could give you a clue what's wrong. 希望这可以为您提供提示,以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.