1
C#에서 간단한 직렬화 및 직렬화 해제 문제가 있습니다.C#에서 날짜 - 시간 필드를 직렬화하면 모델이 항상 null입니다. - Restsharp
RestSharp를 사용하여 webapi 메서드 (REST 메서드)를 호출하고 있습니다.
모델은 다음과 같습니다
public class MyModel
{
public DateTime date {get;set;}
}
컨트롤러 방법 :
[RoutePrefix("Test")]
public class ValuesController : ApiController
{
[Route("~/Date")]
[HttpPost]
public IHttpActionResult Post([FromBody] MyModel model)
{
if (model == null)
return NotOk();
return Ok();
}
}
그러나 xml
를 사용하는 경우 불행하게도, model
는 항상 null입니다.
Restsharp 클라이언트 :
var restRequest = new RestRequest(@"http://localhost:50099/Date", Method.POST)
{
RequestFormat = DataFormat.Xml,
};
restRequest.AddBody(new MyModel(), "");
----> 데이터 형식 xml
경우, 모델은 널이다.
Restsharp 클라이언트 :
var restRequest = new RestRequest(@"http://localhost:50099/Date", Method.POST)
{
RequestFormat = DataFormat.Json,
};
restRequest.AddBody(new MyModel(), "");
-----> 데이터 형식은 JSON이며, 모델은 널 (null)이 아닙니다. date 속성은 기본값입니다.
요청에 대해 피들러 (네트워크) 추적을 실행 했습니까? - 요청의 헤더와 'content-type'이 설정되는 것이 흥미로울 것입니다. –
확인했습니다. 'content-type'이'text/xml' –
으로 설정되어 있고 게시 된 XML이 트레이스에서 어떻게 보이는지 보여 줄 수 있습니까? –