相关疑难解决方法(0)

如何从aspnet请求体中读取原始xml

我需要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?

xml asp.net-core

3
推荐指数
1
解决办法
8063
查看次数

标签 统计

asp.net-core ×1

xml ×1