asp.netjsonhttprequestioexceptionhealth-check

HttpClient request gives HttpRequestException


I developed an healthcheck endpoint for my web application. It prints the following JSON:

{
  "Status": "Healthy",
  "HealthChecks": [
  {
    "Status": "Healthy",
    "Component": "Persistence Server gRPC Status Health Check",
    "Description": "Persistence Server gRPC status is healthy"
  }]
}

This is the health model class:

internal class HealthModel
{
    public string Status { get; set; } = string.Empty;
    public List<HealthCheck> HealthChecks { get; set; } = new List<HealthCheck>();
}

This is HealthCheck class:

internal class HealthCheck
{
    public string Status { get; set; } = string.Empty;
    public string Component { get; set; } = string.Empty;
    public string Description { get; set; } = string.Empty;
}

I have 2 health-check endpoints that uses the exact same model (HealthModel). Those 2 endpoints are running over 2 different ports. For example;

I created a very simple tool with WPF to access those JSON endpoints and consume them.

This is the tool code:

HttpClient httpClient = new HttpClient();
HealthModel? model = await httpClient.GetFromJsonAsync<HealthModel>(url);
return model;

The problem is my tool can connect to https://localhost:7001/h-persistence and consume and print the json content. however, I get HttpRequestException (System.IO.IOException: The response ended prematurely.) when i try to connect the 2nd application.

I compare how i initialize two application and they are identical. I use the same HealthCheck model classes to read their contents but I can read app one's content successfully but app two throws the exception above.

I searched the error already and looked at the solutions in the existing questions on Stackoverflow but no success yet.

Here is what I have tried so far:

Postman Error:

Error: read ECONNRESET
Request Headers
User-Agent: PostmanRuntime/7.31.1
Accept: */*
Postman-Token: c9da74a8-73f1-451f-b145-708dc98d5b72
Host: localhost:7041
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

Here is the error I get:

enter image description here


Solution

  • The information you're showing indicates that there is an error happening on the server, not the client.

    Check 1) the IIS logs to see if it lists an error code, 2) your NT Event logs ("Application" log) for any unhandled exceptions, 3) any (server-side) error handling & logging?