The HttpClient class provides support for invoking the HTTP uniform interface (Get, Post, Put, Delete, Head, etc). And it provides support for processing messages using a variety of different representations. This is made possible through the HttpResponseMessage and HttpContent classes, which provides numerous methods for reading the message body as different representations. Here's a list of the possibilities:
- ReadAsByteArray
- ReadAsDataContract
- ReadAsJsonDataContract
- ReadAsServiceDocument
- ReadAsStream
- ReadAsString
- ReadAsSyndicationFeed
- ReadAsXElement
- ReadAsXmlReader
- ReadAsXmlSerializable
And many of these methods have generic version that allow you to specify a serializable type. You'll need to ensure that you have the appropriate namespace using statement within the file or some of these extension methods may not show up in intellisense.
And between HttpContent and HttpContentExtensions, you also have a similar set of methods for creating request messages from a variety of different formats:
- Create(Byte[])
- Create(Stream)
- Create(String)
- Create (XElement)
- CreateAtom10SyndicationFeed
- CreateDataContract
- CreateJsonDataContract
- CreateRss20SyndicationFeed
- CreateXmlSerializable
Check out this screencast for a complete example that shows how to use some of the methods listed above.