Friday, May 22, 2015

StringContent defaults to text/plain

If your using Microsoft's WebAPI, you probably had to play around with the StringContent class. This class allows you to build content for an HttpResponseMessage. However, the documentation in MSDN is not clear about what you can do with this class. If you enter the more complete constructor, no info at all. So, to create a new Content Object, you could do something like:


new StringContent

(click to enlarge)


Even with just a string it works, but, the Content-Type defaults to text/plain:


new StringContent

(click to enlarge)