Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get this error for a specific website, that they announced they made some changes a couple months ago. Now when I check it through c#.... something is not right. The other websites I check are working allright with this code.
Can someone elucidate it for me, please?
{"The request was aborted: Could not create SSL/TLS secure channel."}

I am using this code:
// I google it and find this 3lines as being helpful - THEY ARE NOT HELPING AT ALL
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.DefaultConnectionLimit = 9999;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls; 
//(In my VS2010, I only see Ssl3 and Tls,that's it - this may be the cause?)

            HttpWebRequest request;
            HttpWebResponse response = null;
            Stream stream = null;
            request = (HttpWebRequest)WebRequest.Create("");
            request.UserAgent = "Foo";
            request.Accept = "*/*";

            request.UseDefaultCredentials = true;
            request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

//{"The request was aborted: Could not create SSL/TLS secure channel."}
//and response is null.
            response = (HttpWebResponse)request.GetResponse();//<<<here it breakes
            stream = response.GetResponseStream();

            if (stream != null) stream.Close();
            if (response != null) response.Close();

Thank you.

What I have tried:

Updated 1-Feb-21 17:31pm

I think i found the solution :
TLS 1.2 and .NET Support: How to Avoid Connection Errors - Perficient Blogs[^]

//in .NET 4.0, TLS 1.2 is not supported, but if you have .NET 4.5 (or above) installed on the system
//then you still can opt in for TLS 1.2 even if your application framework doesn't support it.
//The only problem is that SecurityProtocolType in .NET 4.0 doesn't have an entry for TLS1.2,
//so we'd have to use a numerical representation of this enum value:
//ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
//instead of:
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;

So it was a .NET problem after all. Hmmm.
I am leaving this here with the result i find, maybe it will help others too.
Share this answer
CoolBeans1 12-Sep-19 15:08pm    
Perfect, this resolved the issue..
ajarun03 29-Feb-20 14:26pm    
ServicePointManager.SecurityProtocol = 3072

Perfect one. Hitting for almost a week,
Billion thanks.
Member 2411753 26-Jul-20 8:10am    
I know this is old but I have been stuck on this for over a week. You have saved my life. Thank you!!!
markprichard 14-Jan-21 7:09am    
Thank you, thank you
morzuleti 15-Apr-21 8:51am    
god bless you
<pre>ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 |
                                                   SecurityProtocolType.Tls | SecurityProtocolType.Tls11;
Share this answer
CHill60 26-Mar-19 9:01am    
Did you read the OP's comments in the code .. "//(In my VS2010, I only see Ssl3 and Tls,that's it - this may be the cause?)"
and in their solution "in .NET 4.0, TLS 1.2 is not supported,"
so suggesting that they use it when they can't is not helpful
Add this line
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
It working.
Share this answer
Dave Kreskowiak 9-Sep-19 18:27pm    
The OP answered this themselves last year. Did you even read the solution before posting?
nandox 15-Apr-20 23:58pm    
It Worked for Me!!!!
Thank you very much sir.

I'm using NetFramework 4.5, solution 1 did not worked for me :(
Member 14780208 13-Aug-20 4:39am    
i'm using framework 4.0. it throws me error ServicePointManager does not exist in current context. Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900