The maximum size of an object that can be passed as a parameter to the POST method

I have a web interface API with a POST method as follows.

public class MyController : ApiController
{
    // POST: api/Scoring
    public HttpResponseMessage Post([FromBody]MyClass request)
    {
        // some processing of request object
        return Request.CreateResponse(HttpStatusCode.OK, someResponseObject);
    }
    ....
}

It is consumed by HTTPClient as follows

HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.BaseAddress = new Uri("http://localhost");
MyClass requestClient = new MyClass();
var task = httpClient.PostAsJsonAsync("api/my", requestClient)

It works fine when the size of the MyObject passed in the controller's POST method parameter is small in size. However, in the case when the size of this object is large, I get zero for the request object in the parameters of the POST method. In one case, the size of the requestClient object passed from the request on the client side is ~ 5 MB, and in the POST method I get the request object as null. Note that the web API is hosted in IIS. Is there any parameter that I need to change for a valid size.

UPDATE: web.config POST.

httpRuntime maxRequestLength = "2147483647" /" >

requestClient ~ 50 . POST . , PostAsJsonAsyn, System.Net.HttpRequestException .

: 404 ( ).

maxRequestLength .

+4
1

OP:

> then increased the size of requestClient object to ~50MB. Now the code in POST method never getting hit. On the client side, at the call to PostAsJsonAsyn, I get System.Net.HttpRequestException with following message.

Response status code does not indicate success: 404 (Not Found).

Now changing maxRequestLength doesn’t seem to have any impact.

HTTP-, HTTP- , IIS HTTP 404 HTTP ,

 HTTP Substatus      Description
 404.13                 Content Length Too Large
 404.14                 URL Too Long
 404.15                 Query String Too Long
 ..etc

URL- ( , (IIS) 7.0 ): SERVER MANAGER GUI appcmd.exe Web.

    <configuration>
       <system.webServer>
          <security>
             <requestFiltering>
                 .....

                <!-- limit post size to 10mb, query string to 256 chars, url to 1024 chars -->
                <requestLimits maxQueryString="256" maxUrl="1024" maxAllowedContentLength="102400000" />

                .....
             </requestFiltering>
          </security>
       </system.webServer>
    </configuration>

:

https://www.iis.net/configreference/system.webserver/security/requestfiltering

+6

Source: https://habr.com/ru/post/1651307/


All Articles