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;  
}
Developer technologies ASP.NET ASP.NET Core
Developer technologies ASP.NET Other
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.