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);

JavaScript

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.
List of Attributes
Note: Attribute names are case–sensitive (Method is not equivalent to 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. This function is only generated for requests that cannot 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 Help Center (select the relevant version).

This function is supported for all web scripts.

Attributes

  • URL – the location of the web page to load. The URL can be any of the following protocols: HTTP, HTTPS, or FTP. For authentication, include both the user name and the password in the URL attribute using the following format: ftp://username:password@server/dir/path.
  • Method – any method supported by the HTTP protocol.
  • TargetFrame – the name of the frame containing the current link or resource. SeeTargetFrame for more information.

  • EncType – the encoding method used.

  • EncType specifies a Content–Type, such as "text/html", to be specified as the value of the "Content–Type" REQUEST header for the current replay. web_custom_request performs no body encoding.

  • Any EncType specification silently overrides any web_add_[auto_]header for Content–Type. If "EncType=" (empty value) is specified, no "Content–Type" request header is generated. If "EncType" is omitted, any applicable web_add_[auto_]header is used. If there is no header and "Method=POST", "application/x–www–form–urlencoded" is used as a default. Otherwise, no Content–Type request header is generated.

    The Body argument specifies the body to be used as is. If body encoding is required, it should be applied already to the Body argument as entered in the script. Therefore, specifying an EncType that does not match the body may cause a server–side error. In general, it is recommended that you do not edit the EncType as recorded.

  • RecContentType specifies the "Content–Type" RESPONSE header value as recorded, for example, text/html, application/x–javascript. The RecContentType value is used when the Resource attribute is not specified for determining whether the target URL is a resource or not. For details, see below and see RecContentType and Resource.

  • Referer – the referring web page. The page that referred to the current page. If the location was explicitly expressed, this attribute is omitted.

  • Body, BodyBinary, BodyUnicode, or RAW_BODY_START - one or more of these attributes contains the body of the request. See Body Attribute.

  • Raw Body – a pointer to the request body is passed to the function. See Raw Body Attribute.

  • BodyFilePath – The pathname of the file to be passed as the body of the request. Either specify a full pathname or a pathname relative to the script folder.

    BodyFilePath cannot be used together with Body, or any Body Attribute or Raw Body Attribute: BodyBinary, BodyUnicode, or RAW_BODY_START.

  • Resource – "Resource=1" indicates that the URL is a resource. Failures in downloading resources are reported as warnings rather than errors. Whether to download resources or not is controlled by the "Download non–HTML resources" runtime setting. The response is not parsed as HTML.

    "Resource=0" indicates that the URL is not a resource. If required, the response is parsed as HTML.

  • ResourceByteLimit – See ResourceByteLimit.

  • Snapshot – the file name of the snapshot file.

  • Mode – the Recording Level: HTML or HTTP. See Recording Level / Mode (Web).

  • ExtraResBaseDir – The base URL for resolving relative URLs within the EXTRARES group. URLs can be absolute (like "http://weather.abc.com/weather/forecast.jsp?locCode=LFPO") or relative (like "forecast.jsp?locCode=LFPO"). The actual downloading of URLs is always performed using absolute URLs, so that relative URLs must be resolved using another (absolute) URL as a "base". For example, resolving the relative "forecast.jsp?locCode=LFPO" using "http://weather.abc.com/weather/" as a base will yield "http://weather.abc.com/weather/forecast.jsp?locCode=LFPO". By default, when "ExtraResBaseDir" is not specified, the primary URL of the function is used.

  • UserAgent – "User–Agent" is the name of an HTTP header identifying the application, usually a browser, which represents the user in the interaction with the server.

    For example, the header "User–Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" identifies Microsoft Internet Explorer 6.0 for Windows NT. Other User–Agent strings are used for different browsers and for other, non–browser applications. Usually, all requests from an application use the same User–Agent value, which the recorder specifies as a runtime setting. However, even within a regular browser session, there may be non–browser components (for example, Active–X) that interact with a server directly, and usually have a different User–Agent string than the browser.

    Specifying a UserAgent indicates that this is such a non–browser request. The specified string is used in the "User–Agent:" HTTP header, and affects the Replay's behavior in some points, for example, by not using the browser cache, assuming the specified URLs are resources, etc. No check is made to verify that the specified value is different than that of the browser.

  • ContentEncoding – Requests that the request body by encoded (e.g., compressed) using the specified method (for example, gzip or deflate), and that the corresponding "Content–Encoding:" HTTP header be sent along with the request.

Examples