I need to accept self-signed SSL certificates while developing my C# .NET 4.0 code and I've used the following code from https://stackoverflow.com/a/18624335/1166898
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
I then call this method later in the code:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
When the connection is trusted, response.ContentLength
returns the right length, however, when the connection is untrusted, response.ContentLength
is -1
. The actual content is right in both cases.
How can I get the correct response.ContentLength
with an untrusted (self-signed) connection?