Forum Discussion

Moe_Jartin's avatar
Apr 02, 2010

HTTP::query, How to grab PART of the query parameters?

I am looking to use a query string parameter as part of an authentication profile but I am unsure of the behavior if there are multiple parameters. Example:

 

 

If the URI is /index.html?lang=eng then HTTP::query returns lang=eng

 

 

If the URI is /index.html?lang=eng&locale=US&goto=http://someothersite then HTTP::query returns lang=eng&locale=us&goto=http://someothersite. Right?

 

 

So the question, how do I get just the value of one of the query strings? Say I want get the value of the locale query which US. I know that I can use HTTP::query to set a variable but I don't know how to just grab part of it.

 

 

TIA,

 

 

Joe

2 Replies

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    Split the result from [HTTP::query] on the '&' character. That gives you an array of key=value pairs. Iterate over each of those and split on the '=' character... You'll have key & value.

     

     

    H
  • You can also use URI::query to get the value of a specific parameter in the query string. There's a bug in the parameter value parsing though, so you can use a workaround:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/uri__query

     

     

    [URI::query "?&[HTTP::query] &param_name]

     

     

    Just replace param_name with the name of the parameter you want to retrieve the value for.

     

     

    Aaron