请求正文太大
Request body too large
当我尝试在 Visual Studio 2019 年在 IISExpress 上将一个 80mb 的文件从邮递员上传到我的本地端点 运行 时,出现以下错误:
The request filtering module is configured to deny a request that exceeds the request content length.
所以我将此添加到项目的 applicationhost.config 中:
<system.web>
<httpRuntime maxRequestLength="1050000" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
当我发出 API 请求时,这阻止了错误的发生,但现在我只得到一个 ServiceStack 生成的“快照”页面,告诉我请求花费了多长时间和日期,但我的实际端点从未被击中。
在我的日志中,我可以看到 ServiceStack 抛出了这个异常:
2020-07-20 01:57:56.0497||ERROR|ServiceStackHost|Request body too
large. Microsoft.AspNetCore.Server.IIS.BadHttpRequestException:
Request body too large. at
Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason
reason) at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeRequestIO()
at
Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory1 memory, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory
1
buffer, CancellationToken cancellationToken) at
Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBufferedAsync(Int32
minCount, CancellationToken cancellationToken) at
Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[]
buffer, Int32 offset, Int32 count, CancellationToken
cancellationToken) at
Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream
stream, ArrayPool1 bytePool, Nullable
1 limit, CancellationToken
cancellationToken) at
Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken
cancellationToken) at
Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken
cancellationToken) at
Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm() at
Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form() at
ServiceStack.Host.NetCore.NetCoreRequest.get_FormData() in
C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line
167 at
ServiceStack.HttpRequestExtensions.GetFlattenedRequestParams(IRequest
request) in
C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\HttpRequestExtensions.cs:line
555 at ServiceStack.Host.RestHandler.CreateRequestAsync(IRequest
httpReq, IRestPath restPath) in
C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line
132 at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest
req, IResponse httpRes, String operationName) in
C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line
89|url: |action:
所以 Body 长度仍然需要在某处设置,但我看到的每个地方都指向我已经使用过的配置。
是否需要额外的设置或者这是 ServiceStack 的问题?
我在启动时缺少这个选项:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set default value is: 30 MB
});
当我尝试在 Visual Studio 2019 年在 IISExpress 上将一个 80mb 的文件从邮递员上传到我的本地端点 运行 时,出现以下错误:
The request filtering module is configured to deny a request that exceeds the request content length.
所以我将此添加到项目的 applicationhost.config 中:
<system.web>
<httpRuntime maxRequestLength="1050000" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"/>
</requestFiltering>
</security>
当我发出 API 请求时,这阻止了错误的发生,但现在我只得到一个 ServiceStack 生成的“快照”页面,告诉我请求花费了多长时间和日期,但我的实际端点从未被击中。
在我的日志中,我可以看到 ServiceStack 抛出了这个异常:
2020-07-20 01:57:56.0497||ERROR|ServiceStackHost|Request body too large. Microsoft.AspNetCore.Server.IIS.BadHttpRequestException: Request body too large. at Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason reason) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeRequestIO() at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory
1 memory, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory
1 buffer, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBufferedAsync(Int32 minCount, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool1 bytePool, Nullable
1 limit, CancellationToken cancellationToken) at Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Features.FormFeature.InnerReadFormAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm() at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form() at ServiceStack.Host.NetCore.NetCoreRequest.get_FormData() in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line 167 at ServiceStack.HttpRequestExtensions.GetFlattenedRequestParams(IRequest request) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\HttpRequestExtensions.cs:line 555 at ServiceStack.Host.RestHandler.CreateRequestAsync(IRequest httpReq, IRestPath restPath) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line 132 at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest req, IResponse httpRes, String operationName) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line 89|url: |action:
所以 Body 长度仍然需要在某处设置,但我看到的每个地方都指向我已经使用过的配置。
是否需要额外的设置或者这是 ServiceStack 的问题?
我在启动时缺少这个选项:
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue;
});
services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = int.MaxValue; // if don't set default value is: 30 MB
});