0

I have an ASP.NET Core Web API which is deployed on a server. When I access the Web API endpoint through Postman, I am getting the result, but not when calling through .NET code (HttpClient), instead I'm getting the errors. However, the ASP.NET Core Web API is just working fine when it's running on local machine.

Errors

1 or 4 Error : HttpRequestException: An error occurred while sending the request.

2 or 4 Error : WebException: The underlying connection was closed: An unexpected error occurred on a send.

3 or 4 Error : IOException: Unable to read data from the transport connection: An existing

4 or 4 Error : connection was forcibly closed by the remote host.

When deployed on server, why is it only working through Postman - or when API is running locally?

1
  • Is the application running in the first place? Is it running on 80/443 or a custom port? Does the firewall allow you to connect to that port? Commented Apr 2, 2024 at 14:10

1 Answer 1

0

After setting up the security protocol inside of HttpCLient it works for me.

using (var client = new HttpClient())
{
    var = SecurityProtocolType.Tls | 
        SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.