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

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.

This function is supported for all web scripts.

Attributes

AttributeDetails
URLThe 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.
MethodAny method supported by the HTTP protocol.
TargetFrameThe name of the frame containing the current link or resource. See TargetFrame 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", then "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.

RecContentTypespecifies 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.
RefererThe 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 BodyA 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.

ResourceByteLimitSee ResourceByteLimit.
SnapshotThe file name of the snapshot file.
ModeThe 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.
ResponseTime

Saves the response time to the specified parameter. The response time is the difference between when the request is sent and when the response is received.

Note:

  • Not supported in Java.
  • On Linux load generators, not supported for HTTP 1.1.

Examples

Submit a form

Copy code
web_url("file.html", "URL=http://lazarus/html/forms/file.html",;"TargetFrame=_TOP", LAST );
web_add_header("Content–Type", "multipart/form–data; boundary=–––––––––––––––––––––––––––292742461228954");
web_custom_request("post_query.exe", "Method=POST",
    "URL=http://lazarus/cgi–bin/post_query.exe",
    "Body=–––––––––––––––––––––––––––––292742461228954\r\nContent–Disp"
    "position: form–data; name=\"entry\"\r\n\r\nText\r\n––––––––––"
    "–––––––––––––––––––292742461228954\r\nContent–Disposition: f"
    "–––––––––––292742461228954––\r\n",
    "TargetFrame=",
    LAST );

Read a file into a parameter and then upload it

Copy code
int imageSize;
imageSize = lr_read_file( "image.tiff", "myImage", 0);
if (imageSize == -1) lr_abort();
web_custom_request("postImage.jsp", "Method=POST",
    "URL=http://lazarus/cgi–bin/postImage.jsp",
    "Body={myImage}",
    LAST );

Upload an image using a pointer and the length

Copy code
char* imageBuffer ;    // Points to buffer of binary image data, possibly including null bytes
int imageLen;        // The length of the image
// Populate the image buffer and length.
...
web_custom_request("StepName",
    "URL=http://some.url ",
    "Method=POST",
    RAW_BODY_START,
    imageBuffer, 
    imageLen,
    RAW_BODY_END,
    LAST);

Upload a file using the BodyFilePath

Copy code
web_custom_request("ABC",
    "URL=http://myserver/files",
    "Method=PUT",
    "Resource=1",
    "RecContentType=text/plain",
    "Referer=",
    "BodyFilePath=c:\\temp\\upload.txt",
    LAST);

Get response time

Copy code
web_custom_request("web_custom_request_1",
    "URL=http://web.kalimanjaro.aws.swinfra.net",
    "Method=GET",
    "TargetFrame=",
    "Resource=0",
    "Referer=",
    "Body=",
    "ResponseTime=kalimanjaroResponseTime",
    LAST);
    
lr_log_message("Kalimanjaro response time 1: %s ms", lr_eval_string("{kalimanjaroResponseTime}"));

return 0;