다음과 같이 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에서
가능한 복제 [? POST 요청의 크기 제한은 무엇] (HTTP : //stackoverflow.com/questions/2364840/what-is-the-size-limit-of-a-post-request) – ssbb
@ssbb 그러나이 링크는 API에 대해이 문제를 해결하는 방법을 제공하지 않습니다. IIS에서 호스팅 됨 –