错误的请求数据:“带有'Connection:Upgrade'的请求不能在请求正文中包含内容。”向APi发送POST请求

时间:2019-07-31 14:54:08

标签: c# docker asp.net-core .net-core kestrel-http-server

我创建了一个简单的.NET核心Web API,该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时,此操作也会失败。 在这里可以忽略什么?

1 个答案:

答案 0 :(得分:1)

似乎@mjwills在评论中确实是Jelastic代理。 在Jelastic中,我注册了一个终结点,该终结点将容器中的端口80公开映射到11000,问题似乎已解决。看来,Jelastic中的代理/映射/重新路由更改了请求。