var httpClientHandler = new HttpClientHandler
{
SslProtocols = SslProtocols.Tls12,
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; },
};
var httpClient = new HttpClient(httpClientHandler)
{
BaseAddress = new Uri("https://api.myservice.com:4443"),
Timeout = TimeSpan.FromSeconds(10),
};
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"USER1:PASS1"));
httpClient.DefaultRequestHeaders.Add("Authorization", $"Basic {credentials}");
var result = await httpClient.PostAsync("/login", null);
MyApp.csproj
<PropertyGroup Condition="'$(Configuration)'=='Release' And '$(TargetFramework)'=='net5.0-windows' And '$(RuntimeIdentifier)'=='win-x86'">
<OutputPath>..\..\release\</OutputPath>
<AssemblyName>my-app</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
- my-app.exe is x86 assembly with .NET 5.0
- .NET 5.0 runtimes are installed (both x86 and x64)
- .NET framework 4.8 is installed
- KB3033929, KB3063858 and KB3140245 are installed
- https://api.myservice.com:4443 supports TLS 1.2
it works with Win10 x64 but with Win7 Sp1 x64 it generates:
The SSL connection could not be established, see inner exception.
- the inner exception is empty
I've already added these registry entries:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions"=dword:00000001
"SchUseStrongCrypto"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319]
"SystemDefaultTlsVersions"=dword:00000001
"SchUseStrongCrypto"=dword:00000001