【发布时间】:2023-03-21 17:10:01
【问题描述】:
我创建了一个简单的 .NET 核心 Web API,它可以在 localhost 上完美运行。 每当我将 docker 映像部署到我们的服务器(Jelastic)并 POST 到唯一的 POST 端点时,我都会失败。
错误如下:
INFO 02:41:14 Connection id "0HLOLOJQ1QFRM" bad request data: "Requests with 'Connection: Upgrade' cannot have content in the request body."
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Requests with 'Connection: Upgrade' cannot have content in the request body.
at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.For(HttpVersion httpVersion, HttpRequestHeaders headers, Http1Connection context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.CreateMessageBody()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication`1 application)
所有 GET 请求都成功成功。
[HttpPost]
public ActionResult<List<string>> Post([FromBody]Dictionary<string, string> data)
{
//LOGIC
}
我认为没有反向代理(NGINX 或类似的),一切都由 Kestrel 处理。
我的要求是:
POST /api/word HTTP/1.1
Host: *our server*
Content-Type: application/json
User-Agent: PostmanRuntime/7.15.2
Accept: */*
Cache-Control: no-cache
Postman-Token: 9d575404-6347-4783-a03f-cba29f9113e8,b8a94c5d-1ee5-42c4-a2e4-348c9af0e064
Host: *our server*
Accept-Encoding: gzip, deflate
Content-Length: 110
Connection: keep-alive
cache-control: no-cache
{
"customerName": "test-entries",
"reportPeriod": "test-entries"
}
使用 CURL 时也会失败。 这里有什么可以忽略的?
【问题讨论】:
-
你确定它在本地有效吗?对于
[FromBody],它期望使用Content-Type: application/json发送请求,但您使用Content-Type: text/plain发送请求。 -
感谢您的回复,看来我从我们的测试集中收到了错误的请求,我已经更新了请求,但结果仍然没有区别。
-
您目前的要求是什么?
-
您确定 Jelastic 没有运行反向代理?
-
@mjwills 确实如此。
标签: c# docker asp.net-core .net-core kestrel-http-server