【发布时间】:2020-03-28 15:58:23
【问题描述】:
我正在使用 .NET core 2.2 应用程序。调用 API 时出现 HTTP 错误 404.15。
因为我在 URL 中传递了大量的项目。
而且我无权更改 IIS,如下所述。
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="3000" maxUrl="1000" /> /* Change the Url limit here */
</requestFiltering>
</security>
</system.webServer>
</configuration>
我也尝试了以下解决方案,但都不起作用。
[HttpPost]
[RequestSizeLimit(40000000)]
public async Task<IActionResult> UploadFiles(IFormFile file)
{
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 52428800; //50MB
});
}
app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), appBuilder =>
{
context.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null;
//TODO: take next steps
});
这是我的 API 调用
https://localhost:44473/ControllerName/InsertProduct?ProductSubCategoryId="4"&ProductName="Canon EOS 200D II DSLR Camera EF-S 18 - 55 mm IS STM and 55 - 250 mm IS STM (Black)"&ProductDescription="Is photography one of your passions? Bring home this EOS 200D II from Canon. This is Canon’s lightest DSLR that features a vari-angle LCD touch screen. It features a 24.1-megapixels APS-C CMOS sensor and a DIGIC 8 processor that capture stunning images. The EOS 200D II also has a lot of other features that make everyday photography a lot easier."&ProductSpecification="{"Specification":[{"In The Box": "1 Camera Body, 18 - 55 mm Lens, 55 - 250 mm Lens, Battery, Battery Charger, USB Cable, Camera Bag"},{"Model Number": "EOS 200D II"},{"Model Name": "eos200dii"},{"SLR Variant": "EF-S 18 - 55 mm IS STM and 55 - 250 mm IS STM"},{"Effective Pixels": "24.1 MP"},{"Image Sensor Size": "22.3 x 14.9"},{"Sensor Type": "CMOS"},{"Lens Mount": "EF Mount"},{"Shutter Speed": "1/4000 - 30 sec"},{"Image Format": "JPEG, RAW, C-RAW, RAW + JPEG, C-RAW + JPEG"},{"Video Resolution": "1920 x 1080"},{"Video Quality": "Full HD"},{"Battery Type": "Lithium"},{"Weight": "654g"}]}"&ProductOptions="{"Options":[{"Bank Offer":"10% Instant discount with HDFC Bank PayZapp Card on purchase of Rs.300 or more"},{"No Cost EMI": "Avail No Cost EMI on select cards for orders above ?3000"},{"Partner Offers":"Get FLAT 5% BACK with Amazon Pay ICICI Bank Credit card card for Prime members. Flat 3% BACK for non-Prime members. No minimum order value. No upper limit on cashback."}]}"&ProductPrice="57499"&ProductBrand="Canon"&IsActive="True"&Quantity="50"&ImageURL="NULL"
在控制器中调用方法
public int InsertProduct(Product product)
{
Dictionary<string, object> keyValues = this.GetProperty<Product>(product);
int i = bl.AddProduct<Product>(keyValues);
return i;
}
所以任何人都可以建议我一个更好的想法来解决这个问题。
【问题讨论】:
-
请向我们展示您尝试调用端点的方式,以及您尝试调用的整个操作
-
是的,我会编辑我的问题。
-
你从哪里打电话?只是在地址栏中,还是来自某些代码?
-
等一下.... api 调用显示的是 GET 请求而不是 POST 请求......但是您的 UploadFiles 正在使用 POST... 那么为什么不尝试使用 POST 呢?我也很困惑 UploadFile 或 InsertProduct 调用中的错误在哪里......请显示相关代码
-
我想通了。请看我的回答
标签: c# asp.net-mvc model-view-controller .net-core http-error