Error while sending request

Mohamadshirzad

New member
Joined
Feb 11, 2024
Messages
2
Programming Experience
3-5
Hi, I have a code which in windows 10 works properly but in windows 7 ,I recieve the error :
An error occurred while sending the request. System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) mscorlib

My code:

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

string endPoint = "login";
string Url = $"{BaseUrl + endPoint}?username={getDomain.username}&password={getDomain.password}";


using (var httpClient = new HttpClient())
var httpresponse = await httpClient.GetAsync(Url);
```


Logger.Log.Api(Logger.LogStatus.Success, "Getting " + nameof(GetDomain));
httpClient.DefaultRequestHeaders.Add("Domain", "null");
httpClient.DefaultRequestHeaders.ConnectionClose = true;

var httpresponse = await httpClient.GetAsync(Url);
 
You do realize the Windows 7 has been out of support for the past 4 years, right?

The default TLS versions used by the .NET Framework prior to version 4.6.2 (?) is the deprecated TLS 1.1. You have to make sure you are targeting .NET Framework 4.6.2 or higher, or put in the necessary hack to in your code to force the use of TLS 1.2. If your Win7 box never got the updated .NET Framework, this might be part of the reason why you are getting that error.

Furthermore, you might want to make sure that you have all the latest patches for Windows 7. It might not have the patch that has the supported crypto protocols. Also the patches should have brought the machine up to 4.8.

I had to target 4.6 and put in that hack in code that I wrote years ago because our desktop IT team was pushing out Win7 images that had the older .NET Framework installed, and they refused to create new images with the updated .NET Framework "because it might break some stuff" -- even when I showed them the MS documentation that shows how 4.8 and higher knows how to fallback for compatibility mode.
 
Back
Top Bottom