I am facing an issue with the C# HttpClient's PostAsync method. I am calling an API which is on HTTPS SSL and things are working fine until I deployed my code on to a server which has the following in the web.config
var response = await Client.PostAsync(path, requestObject);
response.EnsureSuccessStatusCode();
string strResponse = response.Content.ReadAsStringAsync().Result;
The API being called is on HTTPS and the certificate is trusted on my machine.
<httpRuntime maxRequestLength="40960" **targetFramework="4.8" **enableVersionHeader="false" />
My local environment doesn't have the targetFramework in the web.config. The API call only works if I remove the TargetFramework attribute. After adding the attribute back, there seems to be no errors or response, the execution hangs for 5 minutes. There is no exception or error, nothing in the event viewer.
I have tried a lot of things like setting the TLS
Security.Transport.SslProtocols = SslProtocols.Tls11 | SslProtocols.Tls12;
and
System.Net.ServicePointManager.SecurityProtocol |=
SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
But nothing seems to work. We need the targetframework attribute and need this api call to work. What is the TargetFramework attribute adding in terms of configuration which is leading to api call failing/hanging ?