StatusCode:404,ReasonPhrase:'Not Found',版本:1.1,内容:System.Net.Http.HttpConnectionResponseContent,

StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent,

{StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: private
  Server: Microsoft-IIS/10.0
  X-Powered-By: ASP.NET
  Date: Sat, 06 Jun 2020 02:26:17 GMT
  Connection: close
  Content-Type: text/html; charset=utf-8
  Content-Length: 5059
}}

在 api 中调用 post 方法生成响应消息而不命中 api 时,我们使用 stringcontent 将输入参数作为序列化 json 传递有 200k 个对象。我们的基本理解是因为内容超出了限制的长度。我们正在使用.net core 3.1。如何增加最大允许长度?我们已经尝试将 [RequestSizeLimit(long.MaxValue)] 置于控制器级别。我们的网络 api 通话

 [Route("~/api/Controller/somemethod")]
 [HttpPost]
public string somemethod(List<DataMaster> Lists)

我们的api调用方法

url = "https://localhost:44339/" + url;
            HttpContent httpContent = new StringContent(inputParams, Encoding.UTF8, "application/json");
            HttpRequestMessage request = new HttpRequestMessage
            {
                Method = new HttpMethod(method),
                RequestUri = new Uri(url),
                Content = httpContent
            };
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

            HttpClient client = new HttpClient(clientHandler);

            return client.SendAsync(request).Result;

您可以设置 MaxRequestBodySize(文档):

Gets or sets the maximum allowed size of any request body in bytes. When set to null, the maximum request length will not be restricted in ASP.NET Core. However, the IIS maxAllowedContentLength will still restrict content length requests (30,000,000 by default). This limit has no effect on upgraded connections which are always unlimited. This can be overridden per-request via IHttpMaxRequestBodySizeFeature.

services.Configure<IISServerOptions>(options =>
{
    options.MaxRequestBodySize = 2147483647;
});