[.net core] 在 Windows 中运行出现 WinHttpException: The parameter is incorrect

有一个 web 服务一直跑在 docker 中,今天需要在 Windows 上部署一个备份版本,于是,签出源代码,编译,运行。结果抛出 500 ,日志中有如下记录:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The parameter is incorrect
   at System.Net.Http.WinHttpException.ThrowExceptionUsingLastError()
   at System.Net.Http.WinHttpHandler.InternalSendRequestAsync(WinHttpRequestState state)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
   --- End of inner exception stack trace ---

异常发生在调用一个其他服务时发生的,根据异常消息:“The parameter is incorrect” 百思不解,刚开始以为是依赖的服务没有部署好,重新部署之后,问题依旧。

外事不决,问 Google:“WinHttpException: The parameter is incorrect”

原来是 WinHttpHandler 无法处理带有 body 的 GET 请求,链接地址:https://github.com/dotnet/corefx/pull/28367

这个 PR 并没有解决这个问题,只是抛出了一个更友好的异常信息。不过没关系,知道了问题的原因,那么解决办法就很简单了:

不在 GET 请求中添加 Body 即可。

posted @ 2018-04-10 16:13  蝌蝌  阅读(904)  评论(0编辑  收藏  举报