我需要HttpController接收原始 XML 并将其传递给遗留代码。我试试这个:
[HttpPost]
[Route("/xml")]
public string Post([FromForm] XDocument xml)
{
return xml.ToString();
}
Run Code Online (Sandbox Code Playgroud)
然而,该xml文档似乎总是空的,例如,
$ curl -k -X POST https://localhost:5001/xml -d '<foo>bar</foo>' -i
HTTP/1.1 200 OK
Date: Fri, 26 Feb 2021 10:19:23 GMT
Content-Type: text/plain; charset=utf-8
Server: Kestrel
Content-Length: 0
$
Run Code Online (Sandbox Code Playgroud)
如何从请求正文中读取原始 XML 并获取有效的 XDocument?