adsense

Tuesday, April 16, 2019

TLS 1.2 suport in .Net 4.5 or above

Even thought Net 4.5 or above supports TLS 1.2, .Net default protocol is TLS 1.0. It is recommended to set the SecurityProtocol before any WebRequest calls.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

var url = "https://www.gmail.com";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

Setting SecurityProtocol before any WebRequest calls will make sure that response will not get following error when getting the response.

"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

No comments:

Post a Comment