UWP API 客户端在响应中引发 ObjectDisposedException。内容并返回部分数据

UWP API Client throws ObjectDisposedException in response.Content and returns partial data

提问人:pft1 提问时间:11/14/2023 更新时间:11/14/2023 访问量:14

问:

我有一个 UWP 客户端,它向 ASP 核心服务器发送 POST 请求以从数据库请求数据。 请求返回成功代码 200,但反序列化数据不完整,并在响应时使用调试器进行检查。内容说:. Position、ReadTimeout 和 WriteTimeout 也是如此。Length = '((System.IO.BufferedStream)(System.Net.Http.StreamContent)response.Content)._content).Length' threw an exception of type 'System.ObjectDisposedException'

我的代码是:

using (HttpClient Http = new HttpClient())
            using (HttpResponseMessage response = await Http.PostAsJsonAsync<ChartDataRequest>(string.Concat("http://localhost:5242/", "MyDbController"), chartDataRequest))
            {
                HttpContent content = response.Content;
                if (response.IsSuccessStatusCode)
                {
                    var chartDataResponse = content.ReadAsAsync<ChartDataResponse>();
                    DataText.Text = chartDataResponse?.Result.ResponseMessage;
                    List<Bic_OHLC> moreCandles = chartDataResponse?.Result.ChartData.OHLCs;

                    SyncMoreCandles(moreCandles);
                }
                else DataText.Text = response.ReasonPhrase;
            }

应该有大约 180 个元素,但这里只返回 100 个元素。 请注意,如果我使用 Blazor wasm 客户端发出相同的 POST 请求,它会返回整个列表。List<Bic_OHLC>

我假设是因为响应对数据的影响很大,并且响应对象在完全读取之前就被处理掉了,但我无法让它工作。请注意,如果这很重要,_bufferSize设置为 0。

发布 UWP ASP.NET-CORE-WEBAPI HTTPCLIENT

评论


答: 暂无答案