.Net Core Web API
컨트롤러 에 대한이 작업이 있습니다 HomeController
.
[HttpPost]
public IActionResult TestMethod([FromForm] DocumentDto xml) {
int abc = 0;
return Ok();
}
및 모델 DocumentDto
:
[XmlRoot(ElementName = "document", Namespace = "")]
public class DocumentDto
{
[XmlElement(DataType = "string", ElementName = "id")]
public string Id { get; set; }
[XmlElement(DataType = "string", ElementName = "content")]
public string Content { get; set; }
[XmlElement(DataType = "string", ElementName = "author")]
public string Author { get; set; }
}
또한에 중단 점을 추가했으며 int abc = 0;
Postman을 사용하여 아래와 같이 작업을 수행합니다.
xml
요청에 대한 사용은 다음과 같다
<document>
<id>12345</id>
<content>This is a Test</content>
<author>vchan</author>
</document>
그러나 디버깅하는 동안 xml
변수에는 null
아래와 같은 속성이 있습니다.
또한 Startup.cs 파일에를 포함했으며 다음 AddXmlSerializerFormatters()
과 같습니다.
services
.AddMvc()
.AddXmlSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
왜 xml
파싱되지 않습니까?
귀하의 요청에 따라 원시 XML 구문 분석해야 [FromBody]
하지 [FromForm]
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다