Stefano_E__1814
Feb 19, 2015Nimbostratus
Get value from HTTP POST request body
Hi all,
I can retrieve the value of the JSON boby for HTTP POST request.
This is the call to F5: curl --insecure -H "Content-type: application/json" -H "Content-Length: 92" -X POST -d '{ \"username\" : \"abc\", \"password\" : \"def\"}'
My iRule code is:
when HTTP_REQUEST {
Keeping request lenght to collect the payload for POST JSON request parameters
if {[HTTP::method] equals "POST"} {
set content_length 0
if { [HTTP::header exists "Content-Length"] } {
if { [HTTP::header "Content-Length"] > 1048000 }{
if {$logDebug}{log local0. "=>|$logId| Content-Length over 1Mb so discard the request\n"}
HTTP::respond 403
return
} else {
set content_length [HTTP::header "Content-Length"]
if {$logDebug}{log local0. "=>|$logId| post request Content-Length is $content_length\n"}
}
} else {
if {$logDebug}{log local0. "=>|$logId| Content-Length HEADER does not exist: discarding the request\n"}
HTTP::respond 403
return
}
Collecting the http request byte
if { $content_length > 0 } {
HTTP::collect $content_length
set payload_collect true
if {$logDebug}{log local0. "=>|$logId| Payload collected. we pass on HTTP_REQUEST_DATA event\n"}
}
}
}
when HTTP_REQUEST_DATA {
==================================================================================
We need to retrieve parameters from POST body
==================================================================================
Looking for json POST parameter
if { $payload_collect } {
set payload [HTTP::payload]
if {$logDebug}{log local0. "=>|$logId| payload: $payload \n"}
I need to retrieve username and password from json
....
}
}
How can I manage the json for retrieve the values of username and password?
Thx, Stefano