HTTPStatusCode 404 in production only, why?

winanjaya 146 Reputation points
2023-02-02T01:50:28.88+00:00

Hi,

What's wrong with my code below, I have tried it in debug mode and got no 404, but if I run it in production (Linux CentOS 8), it fails with 404 (in my case it always fail on pageNo == 2 (there are actually have 20 pages)


List<Task> tasks = new List<Task>();

_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Token", token);

int pageNo = 0;
int iStatusCode = 0;

while (true)
{
    pageNo++;
    iStatusCode = 0;
    var url = new Uri(baseAddress + $"/v2.2/sims/?page=" + pageNo.ToString());

    await _httpClient.GetAsync(url.ToString()).ContinueWith(async (c) =>
    {
        var response = c.Result;

        HttpStatusCode statusCode = response.StatusCode;
        iStatusCode = (int)statusCode;

        if (statusCode == HttpStatusCode.OK)
        {
            response.EnsureSuccessStatusCode();
            if (response.IsSuccessStatusCode)
            {
                JArray ja = new JArray();

                string res = await response.Content.ReadAsStringAsync();
                ja = JArray.Parse(res);
                
                if (ja.HasValues)
                {
                   // Do array process here
                   
                }
         }
    });

     
    if (iStatusCode == (int)HttpStatusCode.NotFound)
       break;  
}
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,212 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,290 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,314 questions
{count} votes