title: Handle Request with application/x-www-form-urlencoded content-type but XML body in NET Core Web API
body: <p>I have a .NET Core 2.1 Web API controller and method that is supposed to consume POST XML requests
  from an external service via HTTP.
  Below is the method header of the controller action.</p>
  
  <pre><code>    [HttpPost]
      [Produces("application/xml")]
      public async Task&lt;IActionResult&gt; PostReceivedMessage([FromBody] ReceivedMessage receivedMessage)
  </code></pre>
  
  <p>I wrote up a custom XML input formatter to process the XML request that works just fine when
  I post a sample XML request from Postman to the app's controller action.
  But when the service sends a similar request, the response from the app has the status 400, Bad Request.</p>
  
  <p>After some debugging, I discovered that the requests come in with </p>
  
  <p><strong>Content-Type: application/x-www-form-urlencoded</strong></p>
  
  <p>instead of application/xml or text/xml as one would likely expect.
  The same behaviour is exhibited by the app if I change the header to match the content-type in the
  request sent by the external service.</p>
  
  <p>I assume that x-www-form-urlencoded is meant for form data because model binding doesn't work
  when I change the action header to:</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; PostReceivedMessage([FromForm] ReceivedMessage receivedMessage)
  </code></pre>
  
  <p>Since I have no control over the external service, how should I make the controller action able to process XML requests with x-www-form-urlencoded as the content-type?</p>
  
  <p>UPDATE:
  Below is a sample request:</p>
  
  <pre><code>POST /check/api/receivedmessages HTTP/1.1
  Cache-Control: no-cache
  Pragma: no-cache
  User-Agent: Java/1.7.0_45
  Host: xxx.xxx.xxx.xxx
  Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
  Connection: keep-alive
  Content-type: application/x-www-form-urlencoded
  Content-Length: 270
  
  &lt;Request&gt;&lt;requestId&gt;95715274355861000&lt;/requestId&gt;&lt;msisdn&gt;345678955041&lt;/msisdn&gt;&lt;timeStamp&gt;2019/10/20 02:23:55&lt;/timeStamp&gt;&lt;keyword&gt;MO&lt;/keyword&gt;&lt;dataSet&gt;&lt;param&gt;&lt;id&gt;UserData&lt;/id&gt;&lt;value&gt;VHVqrA==&lt;/value&gt;&lt;/param&gt;&lt;param&gt;&lt;id&gt;DA&lt;/id&gt;&lt;value&gt;555&lt;/value&gt;&lt;/param&gt;&lt;/dataSet&gt;&lt;/Request&gt;
  </code></pre>