admin管理员组

文章数量:1287119

I am encountering an issue when trying to use the HttpClient in my .NET MAUI application. When making an API call using HttpClient, I receive a response from the server, but the children (or response data) cannot be evaluated correctly, resulting in empty objects or no data being displayed in the UI.

        public async Task<List<ArticleViewModel>> GetAllArticles()
        {
            try
            {
                using (var _httpClient = new HttpClient())
                {
                    // Send GET request to the API
                    string urlEndpoint = _baseUrl + "/api/Articles/GetArticles";
                    var response = await _httpClient.GetStringAsync(urlEndpoint);

                    return JsonConvert.DeserializeObject<List<ArticleViewModel>>(response);

                }
            }
            
            catch (Exception ex)
            {
                return new List<ArticleViewModel>(); // Return empty list on exception
            }
        }

Actual Result: The response is received, but the children (or response data) cannot be evaluated, resulting empty list.

I tried with Postman and another console application, and everything seems fine in both cases. Only in .NET MAUI am I getting the error message

本文标签: NET MAUI HttpClient ResponseChildren Could Not Be EvaluatedStack Overflow