cancel
Showing results for 
Search instead for 
Did you mean: 

HowTo: Inspect and log HTTP POST data

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" ) {  
   log.info( "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:

 

postlog.jpg

 

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

 

Version history
Revision #:
1 of 1
Last update:
‎02-24-2013 07:23:AM
Updated by:
 
Labels (1)