How do you get POST data from http.onrequest?

This has been driving me nuts for about four hours.

How do I extract the POST data from a request sent to http.onrequest()?

I can find out if it’s a post method type with request.method, but I can’t for the life of me get the actual POST data. I thought it would go into a table so I’d put request.query.somekeyname but that doesn’t work.

The example docs don’t explain how to get POST data - I can do this super easy in PHP, yet this is driving me crazy. I’m sure it’s really easy and I’m missing something, but please, someone explain it to me before someone gets hurt!

So I stepped away, looked at the wiki and found: local d = http.urldecode(request.body);

It works.

Panic over!

I add the following code to the top of my http.onrequest() so that all the data is in my request.query table and I don’t have to worry about how it comes into the Agent.

if("content-type" in request.headers){ if(request.headers["content-type"].find("application/x-www-form-urlencoded") != null){ local bodyURLencodedVars = http.urldecode(request.body); request.body = "" foreach(key, val in bodyURLencodedVars){ if(key in request.query && request.query[key] != val){ server.log("Duplicate Key found in URL Encoded Body and Request Query. NOT overriding Query Val="+request.query[key]+" with Body POST Val="+val) } else{ request.query[key] <- val; } } } else if(request.headers["content-type"] == "application/json"){ local bodyJSONVars = http.jsondecode(request.body); request.body = ""; foreach(key, val in bodyJSONVars){ if(key in request.query && request.query[key] != val){ server.log("Duplicate Key found in JSON Encoded Body and Request Query. NOT overriding Query Val="+request.query[key]+" with Body JSON Val="+val) } else{ request.query[key] <- val; } } } }