Forum Discussion
Stefano_E__1814
Nimbostratus
Feb 19, 2015Get 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 '{ ...
nitass
Employee
Feb 19, 2015this is just an example. it may not be fully correct.
configuration
root@(ve11b)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
destination 172.28.24.10:80
ip-protocol tcp
mask 255.255.255.255
profiles {
http { }
tcp { }
}
rules {
qux
}
source 0.0.0.0/0
vs-index 2
}
root@(ve11b)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
proc key2value {l k} {
foreach elm [split $l ,] {
set kv [split $elm :]
if { $k eq [string trim [lindex $kv 0] { }] } {
return [string trim [lindex $kv 1] { }]
}
}
}
when HTTP_REQUEST {
HTTP::collect [HTTP::header Content-Length]
}
when HTTP_REQUEST_DATA {
set payload [HTTP::payload]
log local0. "payload=$payload "
log local0. "username=[call key2value [lindex $payload 0] \\"username\\"]"
log local0. "password=[call key2value [lindex $payload 0] \\"password\\"]"
HTTP::release
}
}
client
[root@centos1 ~] curl -X POST -H "Content-type: application/json" -d '{\"username\" : \"abc\", \"password\" : \"def\"}' http://172.28.24.10
curl: (52) Empty reply from server
[root@centos1 ~]
/var/log/ltm
[root@ve11b:Active:In Sync] config tail -f /var/log/ltm
Feb 19 19:38:15 ve11b info tmm1[14140]: Rule /Common/qux : payload={\"username\" : \"abc\", \"password\" : \"def\"}
Feb 19 19:38:15 ve11b info tmm1[14140]: Rule /Common/qux : username=\"abc\"
Feb 19 19:38:15 ve11b info tmm1[14140]: Rule /Common/qux : password=\"def\"
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects