简体   繁体   中英

Error in System.Net.HttpWebRequest.GetResponse() “ResponceSystem.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel”

Dotnet application is built with dotnet 4.5. On a few system, we are getting this error while connecting to the web server where few changes were made in SSL recently.

Web server TLS only 1.2 https://drive.google.com/open?id=1Z0S-MWugDZdQrIy3BnquooB0ZX7veIVT

Client side code.

WebRequest webRequest = WebRequest.Create(strUrl);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "Get";
if (strUrl.StartsWith("HTTPS", StringComparison.OrdinalIgnoreCase)) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
using (WebResponse webResponse = webRequest.GetResponse())
{
    if (webResponse == null) return blnResult;
    using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
    {
       strSuccess = sr.ReadToEnd().Trim();
       blnResult = true;
    }
}

As soon as I compile it with framework 4.6.2 it works.

Why it is working on few system with same 4.5 compiled EXE and on few system it needs to be compiled with 4.6.2?

WebClient class works fine with 4.5 version of dotnet framework. Only WebRequest is not working.

Need to set security protocol first before initializing WebRequest object.

if (strUrl.StartsWith("HTTPS", StringComparison.OrdinalIgnoreCase)) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;

WebRequest webRequest = WebRequest.Create(strUrl);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "Get";

using (WebResponse webResponse = webRequest.GetResponse())
{
    if (webResponse == null) return blnResult;
    using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
    {
       strSuccess = sr.ReadToEnd().Trim();
       blnResult = true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM