我需要将大量数据发布到我的API
[HttpPost]
[RequestSizeLimit(40000000)]
[Route("PostList")]
public async Task<IActionResult> PostList([FromBody] IEnumerable<ItemMasterDto> data)
{
// Do work
return Ok();
}
要发布的示例数据就像
[
{
"ExternalMappingId": "I-01",
"GroupName": "string",
"SubGroupName": "string",
"DisplayItemCode": "string",
"ItemDescription": "string",
"DispItemDescription": "string",
"ItemSubDescription": "string",
"UnitSet": "string",
"DefaultTranUnitCode": "string",
"DefaultReportUnitCode": "string",
"IsVatExempted": true,
"IsImported": true,
"IsVATApplicable": true,
"IsSaleable": true,
"HSCode": "string",
"VATPercent": 0,
"IsManufacturing": true
}
{
"ExternalMappingId": "I-02",
"GroupName": "string",
"SubGroupName": "string",
"DisplayItemCode": "string",
"ItemDescription": "string",
"DispItemDescription": "string",
"ItemSubDescription": "string",
"UnitSet": "string",
"DefaultTranUnitCode": "string",
"DefaultReportUnitCode": "string",
"IsVatExempted": true,
"IsImported": true,
"IsVATApplicable": true,
"IsSaleable": true,
"HSCode": "string",
"VATPercent": 0,
"IsManufacturing": true
}
]
使用少量数据可以正常工作,但是当我尝试发布更多数据时,则100k数据API拒绝连接,并且我收到呼叫失败,状态码404(未找到)的错误。如您所见,我已经尝试过[RequestSizeLimit(40000000)
,并且在Startup.cs
services.Configure<FormOptions>(o =>
{
o.ValueLengthLimit = int.MaxValue;
o.MultipartBodyLengthLimit = long.MaxValue;
o.MultipartBoundaryLengthLimit = int.MaxValue;
o.MultipartHeadersCountLimit = int.MaxValue;
o.MultipartHeadersLengthLimit = int.MaxValue;
o.BufferBodyLengthLimit = long.MaxValue;
});
我的总数据可能在100k到200k之间。我能做什么 ??谢谢。
答案 0 :(得分:1)
尝试更新您的配置文件requestLimits
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
...
<security>
<requestFiltering>
<!-- This will handle requests up to 50MB -->
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
...
</system.webServer>
</configuration>