Tech Tip: Determine if a web request contains JSON or a Query string
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: October 16, 2014
The code example below demonstrates how to determine if the incoming web request contains a JSON object or a traditional query string.
Sample code
$Type_T:=GetHeaderVar ("Content-Type") If ($Type_T="application/json@") $Data_T:=GetWebVar ("jsonStr") $Request_O:=JSON Parse($Data_T) $UID_T:=OB Get($Request_O;"UID") Else $UID_T:=GetWebVar ("UID") End if |
GetHeaderVar project method
// Project method GetHeaderVar // GetHeaderVar (Text) -> Text // GetHeaderVar (HTTP header name) -> HTTP header content C_TEXT($0;$1) C_LONGINT($vlItem) ARRAY TEXT($names;0) ARRAY TEXT($values;0) $0:="" WEB GET HTTP HEADER($names;$values) $vlItem:=Find in array($names;$1) If($vlItem>0) $0:=$values{$vlItem} End if |
GetWebVar project method
// Project method GetWebVar // GetWebVar (Text) -> Text // GetWebVar (WEB Variable name) -> WEB Variable name C_TEXT($0;$1) C_LONGINT($vlItem) ARRAY TEXT($names;0) ARRAY TEXT($values;0) $0:="" WEB GET VARIABLES($names;$values) $vlItem:=Find in array($names;$1) If($vlItem>0) $0:=$values{$vlItem} End if |