O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Decoding content

The POST request will have some content with it. Decoding this data is simple; we just call the DecodeData() method on the request object. The Content-Type HTTP header determines which decoder will be used when decoding the payload. We will assume plain text will be sent (Content-Type equal to text/plain). This will be decoded into a normal string:

if (!req.HasData) 
   throw new BadRequestException(); 
                                  
string s = req.DecodeData() as string;
You can easily create your own content decoders. This is done by creating a class with a default constructor, implementing the Waher.Content.IContentDecoder interface, and making sure the assembly is initialized in the runtime inventory.

We then use the static Waher.Content.CommonTypes to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required