Spirent Avalanche 5.46 February 29, 2024

HTTP/HTTPS Search

Use ASSIGN VARIABLE in an Action list to search for dynamic data in HTTP/HTTPS responses. You can use the information that the search returns in subsequent HTTP/HTTPS requests. When you search, you look for a string of information that is surrounded by prefix and postfix values that occur one or more times in the data in which you are searching. You also define if you want to search the header, body, or both.

TIP: ASSIGN VARIABLE is useful for searching and retrieving information that occurs between search criteria. If you want to use a search as a conditional statement to perform other actions, use MATCH and MATCHNOT. Action is taken only if there is a match/match not.

You can define search criteria inline within an Action list, or you can use the Search Criteria feature to create a file that defines the prefix, postfix, and postfix occurrence.

NOTES: If you create a search criteria file, and then identify that file as the String 2 value for an inline search, the search ignores any information in the criteria file. Instead, the search uses the prefix, postfix, and integer values defined inline.

To include special characters in a search, such as \n and &, use escape sequences, as described in Using Escape Sequences.

Syntax

You can use several different syntax to define a search.

Syntax 1

ASSIGN VARIABLE <string1 string2 integer1 variable_location>

This search uses separate search criteria defined in a file, to specify prefix, postfix, and post occurrence. Separate search criteria are useful when the prefix and postfix values are used often in tests. To create the search criteria file (identified as string2 ), see Create New Search Criteria.

NOTES:

  • The following syntax examples include a description of integer values that you can use to define lower and upper bounds when searching for an occurrence of an item. If the bounds that you set exceed the occurrence of the search criteria, then Commander uses the last occurrence found. For example, if you define the lower bound as 6 and the upper bound as 10, but the search criteria pattern only appears four times in your search, Commander uses the fourth occurrence.
  • To perform a non-overlapping search, use lower and upper occurrence bounds, as shown in Syntax 2 and Syntax 4 below. The bounds result in the search using a random occurrence within the bounds. To perform an overlapping search, use static search criteria, as shown in Syntax 1 and Syntax 3. For more information, see Overlapping and Non-overlapping Searches.

Syntax 2

ASSIGN VARIABLE <string1 string2 integer1 integer2 variable_location>

This search uses a random value for an occurrence of the search criteria that is between the lower and upper occurrence bounds. For example, if the bounds are 3 and 6, the occurrence of your search criteria could be 3, 4, 5, or 6. To create the search criteria file (identified as string2), see Create New Search Criteria.

NOTE: If a search criteria file with the same name exists in a user interface definition, it will be overwritten by the new assignment. It's recommended that you use unique names for each search criteria file.

Syntax 3

ASSIGN VARIABLE <string1 string2 string3 string4 integer1 integer2 variable_location>

This search uses inline definitions of the prefix and postfix strings. Enter a name for the temporary search criteria file identified as string2. You do not need to create this file ahead of time.

Syntax 4

ASSIGN VARIABLE <string1 string2 string3 string4 integer1 integer2 integer3 variable_location>

This search uses inline definition of the prefix and postfix strings. It uses a random value for the occurrence of the search criteria that is between the lower and upper occurrence bounds. For example, if the bounds are 3 and 6, the occurrence could be 3, 4, 5, or 6. Enter a name for the temporary search criteria file name identified as string2. You do not need to create this file ahead of time.

Examples

Search for text

The following example uses Syntax 3, as described previously, to define a search that looks for a string of data that is preceded by password and followed by end. It searches for the second occurrence of end, and then it looks for the third occurrence of the entire search criteria pattern.

ASSIGN VARIABLE <password_name my_search "password" "end" 2 3 body>

After you assign a variable, such as password_name in the previous example, you can apply it to the next request to the server by using the Apply command. You can also use search criteria to randomly store values.

Search for date

The following example shows you how you would search a header to find the date in the following HTTP server response: Date: Thus, 08 Oct 1998 16:17:52 GMT

The example uses Syntax 3, as described previously.

ASSIGN VARIABLE <found_date New_search "Date" "GMT" 1 1 header>

Search overlapping data

If you use static search criteria, Commander performs an overlapping search of the data. The results from an overlapping search might be different than the results of a non-overlapping search. For more information, see Overlapping and Non-overlapping Searches.

The example uses Syntax 3, as described previously, to search for an ID in the body. If the occurrence of the search criteria is 2, then the second occurrence of the entire search criteria pattern is found. The returned search value is the data between the first 1 and the second 2 of the second occurrence of the search criteria.

ASSIGN VARIABLE <myid temp_file "1" "2" 2 2 body >


HTTP/HTTPS Apply

HTTP/HTTPS Assign Variables

Create New Search Criteria

HTTP Match and Match Not

Overlapping and Non-overlapping Searches

Using Escape Sequences

© 2024 Spirent Communications, Inc. All Rights Reserved.