Forum Discussion

MonkeyWrench_10's avatar
Icon for Nimbostratus rankNimbostratus
Aug 31, 2011

How to inspect POST data on HTTP_REQUEST




I'm trying to route users based on the payload of a POST request, and failing :)




Here's a simplified version of my iRule:






HTTP::collect 100


if { [HTTP::method] equals "POST" } {


HTTP::collect [HTTP::header "Content-Length"]


log local0. "CONTENT LENGTH 1 = [HTTP::header "Content-Length"]"


log local0. "CONTENT LENGTH 2 = [HTTP::payload length]"


log local0. "CONTENT = [HTTP::payload 100]"


log local0. "URI: --[HTTP::uri]--"


if { [HTTP::payload 100] starts_with "SCREEN_ID=" } {


log local0. "PAYLOAD IS NOT EMPTY: [HTTP::payload 100]"






pool QAMEFT02E1NaviNetHTTPBrowser







Log output shows the payload is always empty, even though it's not. The log statement appear to conflict - [HTTP::header "Content-Length"] returns the correct value, [HTTP::payload length] always returns 0, and [HTTP::payload 100] always returns empty string.




Am I doing this wrong? What's the correct way to grab POST request payload? Thanks in advance,






4 Replies

  • Colin_Walker_12's avatar
    Historic F5 Account
    Is there a reason your HTTP::collect line is commented out? Have you tried uncommenting it? ;)



  • HTTP::payload should normally return any payload bytes received in the first packet containing the HTTP headers.

    Regardless to guarantee collection of the full HTTP payload, you need to call HTTP::collect. Make sure to limit collect to less than 4Mb to avoid a TMM crash:

    when HTTP_REQUEST {
      if {[HTTP::method] eq "POST"}{
         Trigger collection for up to 1MB of data
        if {[HTTP::header exists "Content-Length"] && [HTTP::header "Content-Length"] <= 1048576}{
          set content_length [HTTP::header "Content-Length"]
        } else {
            set content_length 1048576
         Check if $content_length is not set to 0
        if { content_length > 0} {
          HTTP::collect $content_length
       do stuff with the payload
      set payload [HTTP::payload]