gpt4 book ai didi

c# - HttpClient : Unable to read data from the transport connection

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:19 26 4
gpt4 key购买 nike

我正在使用 HttpClient (System.Net.Http) 发送 GET 请求,偶尔会遇到以下异常:

无法从传输连接读取数据。在读取所有数据之前连接已关闭。预期 894 字节,读取 0 字节。

我使用的 HttpClient 实例是静态的,as Microsoft recommends ,我将 Connection header 设置为“keep-alive”。我正在为每个请求设置 Authorization header 并使用以下代码发送请求:

        var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _authorizationHeader);

var response = await HttpClient.SendAsync(request);

在代码段的最后一行抛出异常。谁能帮我弄清楚是什么原因导致抛出此异常?

最佳答案

此异常源于描述的问题 here .

修复是下载IIS Crypto并在所有相关服务器上将模板设置为最佳实践(需要重新启动)。

关于c# - HttpClient : Unable to read data from the transport connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43812850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com