Reputation: 1138
I am trying to catch the XML that is contained in the HTTP Request that a server is sending me, but the HTTP doesn't contain a Content-Type. I don´t have access to the server, so I can´t add the Content-Type.
If I try to bind the request body with [FromBody] I get an error of 415 Unsupported Media Type
[HttpPost("voicebiometricsengine")]
public async Task<IActionResult> VoiceBiometricsEngine([FromBody] XmlDocument analytics)
{
return Ok();
}
And If I try to get the body as a string the string comes Null
[HttpPost("voicebiometricsengine")]
public async Task<IActionResult> VoiceBiometricsEngine(string analytics)
{
return Ok();
}
You can see the HTTP package in the next image:
Upvotes: 0
Views: 852
Reputation: 16801
Without the content type, the framework doesn't know how to parse the body when trying to bind with your method parameters.
One option is instead to read the request body manually inside of the method
[HttpPost("voicebiometricsengine")]
public async Task<IActionResult> VoiceBiometricsEngine(string analytics)
{
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var body = await reader.ReadToEndAsync();
}
return Ok();
}
Upvotes: 1