2013-06-29 2 views
0

웹 API에 뭔가 POST하려고하지만 모델 값이 항상 null로 설정됩니다.POST 요청에서 값을 가져 오지 못하는 모델

나는 다음과 같은 요청 (피들러에서 복사 추적) 시도 :

POST http://localhost:53176/api/Profile HTTP/1.1 
Host: localhost:53176 
Connection: keep-alive 
Content-Length: 40 
Accept: application/xml, text/xml, */*; q=0.01 
Origin: http://localhost:53176 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 
Content-Type: application/x-www-form-urlencoded 
Referer: http://localhost:53176/SignUp 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Cookie: ASP.NET_SessionId=do5ddqwghl3v0bhlgr3pyicb 

{"InputEmail":"aa","UserName":"asd"} 

업데이트를 또한 다음과 같은 :

//here I have also tried [FromBody] 
    public MyDto Post(MyDto input) 
    { 
     return input; 
    } 
:

POST http://localhost:53176/api/Profile HTTP/1.1 
Host: localhost:53176 
Connection: keep-alive 
Content-Length: 44 
Accept: application/json, text/javascript, */*; q=0.01 
Origin: http://localhost:53176 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 
Content-Type: application/json 
Referer: http://localhost:53176/SignUp 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Cookie: ASP.NET_SessionId=do5ddqwghl3v0bhlgr3pyicb 

{"InputEmail":"asdas","UserName":"dasd"} 

내 API는 같다

MyDto에는 두 가지 속성이 있습니다. 이 코드는 다음과 같습니다.

public class MyDto 
{ 
    string InputEmail { get; set; } 
    string UserName { get; set; } 
} 

이 코드의 문제점 또는 내가 누락 된 것이 있으면 알려주시겠습니까?

webapi가 역 직렬화를 시도하기 전에 실제 요청이 무엇인지 확인하기 위해 디버거를 webapi 코드의 어딘가에 넣을 수있는 방법을 알고 싶습니다.

답변

1

Content-Type 헤더가 이지만 신체에 json 데이터가 있습니다. 로 콘텐츠 형식 헤더를 수정하거나 application/json 또는 text/json

편집 : 은 당신의 재산

+0

그것뿐만 아니라 그것으로 작동하지 않습니다 어떤 Public을 확인합니다. 새 요청으로 질문을 편집했습니다. – sttaq

+1

'Content-Type : text/json; charset = UTF-8'도 작동하지 않았습니다. 가능하다면 – sttaq

+0

을 디버거를 어딘가에 넣어서 역 직렬화를 시도하기 전에 실제 요청이 무엇인지 확인하십시오. – sttaq

관련 문제