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

Parsing the form

The form will be sent using a Content-Type of application/x-www-form-urlencoded. This type is recognized by Waher.Content, and so decoding is simple. The form will be parsed into a string dictionary. All we need to do is to check that we get what we expect, and that the form has the correct parameters:

if (!req.HasData || req.Session == null) 
   throw new BadRequestException(); 
 
object Obj = req.DecodeData(); 
Dictionary<string, string> Form =  
   Obj as Dictionary<string, string>; 
 
if (Form == null || 
   !Form.TryGetValue("UserName", out string UserName) || 
   !Form.TryGetValue("Password", out string Password)) 
{ 
   throw new BadRequestException(); 
} 

We also need to check the source of the original request, in case we want to redirect the ...

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