gpt4 book ai didi

c# - HttpClient中 "The server returned an invalid or unrecognized response"的含义

转载 作者:太空狗 更新时间:2023-10-29 19:46:26 25 4
gpt4 key购买 nike

等待 <a href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient" rel="noreferrer noopener nofollow">HttpClient</a>.PostAsync 时响应,有时我会看到一条错误消息,指出 “服务器返回了无效或无法识别的响应”:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The server returned an invalid or unrecognized response
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()

这是一个非常神秘的错误;我想我可以想象“无效”响应可能是什么(即句法无效的 HTTP 响应,比如直接跳转到没有状态行的 header ),但到底什么是对 HTTP 的“无法识别”响应要求?该消息似乎是胡说八道。

在什么情况下实际上会触发此错误?

最佳答案

当使用 http 方案调用调用仅 https 的端点时,您可以 100% 地重现这一点。因此,例如在以下位置调用 API:

https://www.mysecureapi.com

使用

http://www.mysecureapi.com

关于c# - HttpClient中 "The server returned an invalid or unrecognized response"的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45843714/

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