首页 新闻 会员 周边

.NET Core 6.0 出现BadHttpRequestException异常 Unexpected end of request content

0
悬赏园豆:15 [已解决问题] 解决于 2022-04-16 07:13

不知道大神有没有遇到过,在请求对方post过来的数据时,出现这个异常
详细堆栈如下:

Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected end of request content.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ContentLengthMessageBody.ReadAsyncInternal(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 destination, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at Agoda.Order.WebApi.Controllers.AgodaController.GetRequestBodyAsyncTRequest in E:\svn\XiWan.OTA\Agoda.Order\src\Agoda.Order.WebApi\Controllers\AgodaController.cs:line 185
at Agoda.Order.WebApi.Controllers.AgodaController.HotelSearch() in E:\svn\XiWan.OTA\Agoda.Order\src\Agoda.Order.WebApi\Controllers\AgodaController.cs:line 113

虔城墨客的主页 虔城墨客 | 初学一级 | 园豆:185
提问于:2022-04-09 14:11
< >
分享
最佳答案
0

这是正常的异常,可以忽略

收获园豆:15
dudu | 高人七级 |园豆:31003 | 2022-04-09 14:12

这种问题不可避免吗?比例挺高的,我统计了一下差不多1/3了,这种是不是队列请求排队超时导致的,但是怎么配置,都会一直出现,出现读取Request.Body 为空的情况。

虔城墨客 | 园豆:185 (初学一级) | 2022-04-11 10:17
其他回答(4)
0

错误在 E:\svn\XiWan.OTA\Agoda.Order\src\Agoda.Order.WebApi\Controllers\AgodaController.cs:line 113
你这里是不是有读取读取Request.Body的操作

jzblive | 园豆:428 (菜鸟二级) | 2022-04-10 04:25

有的,读取了requestBofy

using (StreamReader sr = new StreamReader(Request.Body))
{
content =await sr.ReadToEndAsync();
RequestBody = content;
}

支持(0) 反对(0) 虔城墨客 | 园豆:185 (初学一级) | 2022-04-11 10:15

@虔城墨客:
在前面加上 一句Request.EnableBuffering();

支持(0) 反对(0) jzblive | 园豆:428 (菜鸟二级) | 2022-04-11 11:31

@jzblive: 试过了,没用

支持(0) 反对(0) 虔城墨客 | 园豆:185 (初学一级) | 2022-04-11 14:05
0

您好,问题有解决吗?

我是沈大侠 | 园豆:404 (菜鸟二级) | 2023-09-14 00:51
0

你好,解决了么 我也遇到这个问题,很小的一程序 隔一段时间就会这样线程打满

裁决、 | 园豆:202 (菜鸟二级) | 2023-12-08 23:33
0

读取完成后要重置到0位置,否则下一个代码读不到这个内容,数据流的游标

PasteSpider | 园豆:202 (菜鸟二级) | 2024-02-22 16:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册