ASP.NET MVC4 WebAPI and Posting XML data

[Originally Posted By]: http://stackoverflow.com/questions/10428177/asp-net-mvc4-webapi-and-posting-xml-data

The following will allow you to read a raw XML message via a POST to a Web API method:

public void PostRawXMLMessage(HttpRequestMessage request)
{
   var xmlDoc = new XmlDocument();
   xmlDoc.Load(request.Content.ReadAsStreamAsync().Result);   
}

You can debug and inspect the body, headers, etc. and will see the raw XML posted. I used Fiddler’s Composer to make a HTTP POST and this works well.

shareedit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s