title: How to read raw xml from request body in aspnet
body: <p>I need my <code>HttpController</code> to receive raw XML and pass it on to legacy code. I try this:</p>
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  [Route(&quot;/xml&quot;)]
  public string Post([FromForm] XDocument xml)
  {
      return xml.ToString();
  }
  </code></pre>
  <p>However, the <code>xml</code> document seems to be always empty, e.g.,</p>
  <pre class="lang-sh prettyprint-override"><code>$ curl -k -X POST https://localhost:5001/xml -d '&lt;foo&gt;bar&lt;/foo&gt;' -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
  
  $
  </code></pre>
  <p>How do I read raw XML from the request body and obtain a valid XDocument?</p>