2016-08-15 1 views
3

다음과 같이 POST 메서드가있는 웹 API 컨트롤러가 있습니다. 제어기의 POST 메소드 파라미터 전달을 MyObject 물체는 크기가 작은 때 잘 작동POST 메서드에 매개 변수로 전달할 수있는 개체의 최대 크기

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) 

다음

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

는 세션 객체에 의해 소비된다. 그러나이 개체 크기가 큰 경우 POST 메서드 매개 변수에서 요청 개체에 대해 null이 반환됩니다. 한 경우 클라이언트 측 요청에서 전달 된 requestClient 객체의 크기는 ~ 5MB이며 POST 메서드에서는 요청 객체를 null로 가져옵니다. 웹 API는 IIS에서 호스팅된다는 점에 유의하십시오. 허용되는 크기를 변경해야하는 설정이 있습니까?

UPDATE : 은 Web.config의에서 다음은 POST 메서드 매개 변수에 널 객체 문제를 해결 추가.

httpRuntime을 maxRequestLength의 = "2147483647"/>

그럼 ~ 50메가바이트에 requestClient 개체의 크기를 증가했다. 이제 POST 메서드의 코드가 절대 적중하지 않습니다. 클라이언트 측에서 PostAsJsonAsyn에 대한 호출에서 다음 메시지와 함께 System.Net.HttpRequestException이 발생합니다.

응답 상태 코드가 성공을 나타내지 않습니다 : 404 (찾을 수 없음).

이제 maxRequestLength를 변경해도 영향을 미치지 않습니다. OP에서

+1

가능한 복제 [? POST 요청의 크기 제한은 무엇] (HTTP : //stackoverflow.com/questions/2364840/what-is-the-size-limit-of-a-post-request) – ssbb

+0

@ssbb 그러나이 링크는 API에 대해이 문제를 해결하는 방법을 제공하지 않습니다. IIS에서 호스팅 됨 –

답변

4

:

> 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 

을 ((IIS에 도입 된 내장 보안 기능) 위 7.0)가 있어야한다 구성된 : SERVER MA에 의해 NAGER GUI 또는 명령 유틸리티 Appcmd.exe에 또는 수정의 Web.config

구성 세부 사항 검토를 위해
<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

관련 문제