2014-02-24 3 views
2

매우 간단한 WebAPI 컨트롤러 (모든 시스템 기본값)가 있는데 게시 할 때 Content-Type : application/json이라는 사실이 있습니다. (피들러에서) 게시물을 중단 (돌아 오지 않음)시킵니다. 다음과 같이 Application/json 헤더가있는 WebAPI Post를 호출 할 때 응답 없음

내 헤더

은 다음과 같습니다

Content-Length: 2 
Content-Type: application/json 

및 게시물의 몸은 단순히

[] 

내 WebAPI 컨트롤러는 바로 다음과 같습니다

namespace WebAPI.rest 
{ 
public class SendGridController : ApiController 
{ 

    public HttpResponseMessage Post() 
    { 
     try 
     { 
      HttpContent requestContent = Request.Content; 
      string json = requestContent.ReadAsStringAsync().Result.Trim(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

     return new HttpResponseMessage(HttpStatusCode.OK); 

    } 

나도 같은 걸 때 게시물 (피들러 포함)을 http://respondto.it/으로 보내면 문제가 없습니다.

답변

1

문제는 webapi의 이전 버전으로 밝혀졌다. webapi2로 업데이트하면 문제가 해결되었습니다.

1

ASP.NET에서 실행중인 경우 .Result은 현명한 아이디어가 아닙니다. 자체 호스트에서 코드를 실행했는데 정상적으로 작동했습니다.

이 시도

public class SendGridController : ApiController 
{ 

public async Task<HttpResponseMessage> Post() 
{ 
    try 
    { 
     HttpContent requestContent = Request.Content; 
     string json = await requestContent.ReadAsStringAsync(); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 

    return new HttpResponseMessage(HttpStatusCode.OK); 

} 

}

관련 문제