Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is that possible to send HttpWebRequest using TLS1.2 on .NET 4.0 framework

People also ask

What version of TLS does .NET 4.0 use?

NET 4.0 only supports TLS v1. 0 and there is no standard way of forcing to use never TLS version.

What version of TLS does .NET 4.5 use?

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.

How do you check if TLS 1.2 is enabled?

Click on: Start -> Control Panel -> Internet Options 2. Click on the Advanced tab 3. Scroll to the bottom and check the TLS version described in steps 3 and 4: 4. If Use SSL 2.0 is enabled, you must have TLS 1.2 enabled (checked) 5.


Yes, it supports it but you must explicitly set the TLS version on the ServicePointManager. Just have this code run anytime (in same app domain) before you make the call to Experian:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

Update

see @iignatov 's answer for what you must do for framework v4.0. My code works with 4.5+


I had to deal with the same problem, while integrating PayPal into a legacy application, and found the following workaround for .NET 4.0 which seems to do the trick:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;

Basically the workaround is to directly assign the port for TLS 1.2.

All credit goes to the commenter at CodeProject.


The VB.NET Translation of iignatov's answer:

ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
ServicePointManager.DefaultConnectionLimit = 9999

I was solved with this way.

    string url = "https://api.foursquare.com/v2/blablabla...";
    var request = (HttpWebRequest)WebRequest.Create(url);

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    
    var response = (HttpWebResponse)request.GetResponse();
    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

You can also use this:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | (SecurityProtocolType)768 | (SecurityProtocolType)3072;