Hi I am trying to do a HttpRequest to a website and when I call GetRequestStream()
I keep getting this Error.
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.
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.