vADC Docs

HowTo: Inspect and log HTTP POST data

by on ‎02-24-2013 07:23 AM - edited on ‎06-10-2015 09:37 AM by PaulWallace (2,905 Views)

Should you ever need to inspect or log POST body data in an HTTP request, the following code snippet may help:


$url = http.getPath();  
$method = http.getMethod();  
$body = http.getBody();  
if( $method == "POST" ) { "POST ".$url."; Hex-encoded body: ".string.hexencode( $body ) );  


The TrafficScript function http.getBody() will return the entire HTTP POST body (not the headers of course), or will return the empty string if there was no body provided. The entire body is buffered up in memory (you can pass an optional 'length' parameter to limit how much data is buffered).


This function logs the POST body as follows:




This capability is useful if you want to log a post body is for debugging or record keeping. However, there are many reasons why you might want to gather the post data (to inspect, transform, validate or route traffic) and the same principles apply. One good example is when processing SOAP traffic; you want to read the XML payload, check it against a DTD, perhaps transform it, and then route the traffic based on the method in the request.


Read More