I am using HttpClient.PostAsync to call a REST web service (Unified Endpoint Management, but I doubt that is relevant) on a remote (internal LAN) server. The call is throwing an exception as follows:
10/15/2020 5:05:25 AM An error occurred while sending the request.
10/15/2020 5:05:25 AM at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
10/15/2020 5:05:25 AM The underlying connection was closed: An unexpected error occurred on a send.
10/15/2020 5:05:25 AM at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
10/15/2020 5:05:25 AM Authentication failed because the remote party has closed the transport stream.
10/15/2020 5:05:25 AM at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
The error seems to indicate some kind of TLS error. The certificate is issued by an internal CA which is trusted through Group Policy. I can do the exact same call by pasting the JSON data, URL and headers into Postman, and it works. I can open the server URL in Firefox without a problem, although on Edge I get an error "Turn on TLS 1.0, TLS 1.1, and TLS 1.2 in the Advanced settings," but doing that changes nothing either on the .NET service on in Edge. I have also done the same in .NET by specifying the TLS options to 1.0, 1.1 and 1.2 manually. I've done likewise for SSL 2.0 and SSL 3.0, but nothing changes.
According to the software vendor, it should be using TLS 1.2. I cannot change much server side as it's proprietary software.
Any ideas? I need to get this working again, but the code hads't changed since before the server was updated and the REST API specification remains the same (confirmed by Postman).
I’m running the code on .NET Framework 4.6.1 (ASP.NET). The flow is a bit strange as I have a web interface running on PHP (Laravel) on one server, which sends a call to a .NET web service on another server (this is where I’m running into the problem), that server in turns calls a Tomcat server and also performs tasks in .NET.