Web Vuser Functions (WEB) > Alphabetical List of Web Vuser Functions > web_custom_request

web_custom_request

Allows you to create a custom HTTP request with any method supported by HTTP.

C Language

int web_custom_request( const char *RequestName, <List of Attributes>, [EXTRARES, <List of Resource Attributes>,] LAST);

Java Language

int object.custom_request( const char *RequestName, <List of Attributes>,[EXTRARES, <List of Resource Attributes>,] LAST);

Argument
Description
object
An expression evaluating to an object of type WebApi. Usually web for Java. See also Function and Constant Prefixes.
RequestName
The name of the step, as it appears in the graphical script.
List of Attributes
Note: Attribute names are case–sensitive (Method vs. method).
EXTRARES
A demarcation parameter indicating that the next parameter will be a list of resource attributes.
List of Resource Attributes
LAST
A marker that indicates the end of the field list.

Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.

Parameterization

All attributes from the List of Attributes and the List of Resource Attributes can be parameterized, using standard parameterization.

General Information

The web_custom_request function is an action function that allows you to create a custom HTTP request using any method or body. (Each Web Action Function in a script causes the browser to display a new Web page or frame. All Web Action functions can be recorded by VuGen.) By default, VuGen generates this function only for requests that could not be interpreted with other web functions.

To insert this function manually, use the Add Step dialog box. To specify an HTTP header to be sent before the custom request, add a web_add_header or web_add_auto_header function.

The Extra Resource Attributes are only inserted when performing HTML-based recording and the "Non HTML-generated elements" advanced recording option is set to Record within the current script step. This is the default setting. For more information, refer to the Virtual User Generator User Guide.

This function is supported for all Web scripts.

Attributes

BODY handling in C scripts

Often key data to be correlated or parameterized is part of the request Body. If the data being sent is very large, VUGen splits the body attribute into multiple strings containing about 1000 characters per line.

In C, adjacent strings are automatically concatenated by the compiler. So these are equivalent:

char *example = "abcd" "efgh";
char *example = "abcdefgh";

Tip: You can break long lines recorded by VUgen into smaller portions to make it clearer what you are correlating or parameterizing.

For example, if this is recorded: 

    "Body=ExampleText=A really long set of information that remains
     the same &ExampleText2=More constant data &INCIDENT={incidentToLookup}&VIEWSTATE={ViewStateCorrelation}",
    LAST);

You can split the Body string into multiple strings to see what is being correlated or parameterized more clearly:

    "Body=ExampleText=A really long set of information that remains the same &ExampleText2=More constant data"
    "&INCIDENT={incidentToLookup}"
    "&VIEWSTATE={ViewStateCorrelation}",
    LAST);

Using Binary Code

You can use the following format to include binary code in the Body parameter of a web_custom_request function:

\x[char1][char2]

This represents the hexadecimal value that is represented by [char1][char2].

For example: \x24 is 16*2+4=36, which is a $ sign; \x2B is + sign.

Sequences that do not represent valid 2–character hexadecimal sequences are treated by VuGen as ASCII text. Do not use 1–character hexadecimal sequences. For example, "\x2" is not a valid 2–character hexadecimal sequence. Use "\x02", instead.

Note that binary values appear in a script as \\x, i.e., the "x" is preceded by two backslashes. This is due to C language escaping laws. However, when generating a web_custom_request function by using VuGen, you need to type only one backslash.

If you use parameterization within a web_custom_request function, include only one backslash within the definition of the parameter. This is because parameter substitution does not perform any C escaping conversion.

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a Web page only on certain conditions. To modify the HTTP header in the request, see web_add_header. To modify all subsequent requests, see web_add_auto_header.