Webapi post request returns Null exception

I have a simple post method in a Web API controller that accepts HttpRequestMessage . Somehow, XML does not get parsed until HttpRequestMessage . I configured the application to use XmlSerializer

Trying to pass plain XML to it, but giving me a Null reference exception

 public class SyncSubscriptionController : ApiController { [HttpPost] public HttpResponseMessage Post(HttpRequestMessage req) { var data = req.Content.ReadAsStringAsync().Result; } } 

Sending a request from Fiddler:

 User-Agent: Fiddler Host: localhost:11033 Content-Length: 1852 Content-Type: text/xml Body: <customer> <customer_id>1234</customer_id> </customer> 

Global.asax

 GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true; 
+5
source share

Source: https://habr.com/ru/post/1259623/


All Articles