The fields of the HTTP task can contain C# code and can be used for managing request and response data.

Prepare Script

The C# script can be used for specific POST, GET, and URL data. For example, it can be a random number generator, or it can be for pulling atypical parameters. It can be used, for example, to generate a dynamic URL depending on previous requests (for example, if it gives less than 1000 links – open URL “A” if more than 1000 links then open URL “B”).

Also, the Prepare Script code enables response or request headers modification, network throttling, and redirecting the device traffic through the specified proxy server as shown in the example below.


DotcomProxyProperties.ExternalProxyServerUri = new Uri("<custom proxi URL>:<port number>");

Post Script

By default, the device report does not include a description of responses. The C# Post Script can be applied to the response to track any custom information in the response as cookies or a header description. In addition, an assertion can be added to validate a specific response header for specified content and generate an error if the condition is not met.

Example 1. Print a header in the description:

var svHdr = (Tasks["twitter"] as Http).Response.Headers["Server"] ;
Assert("[Server] Header validation failure. Value is: " + svHdr, () => svHdr != null && svHdr.Contains("Cisco Umbrella"));
Response.Description = "Server: " + svHdr;

Example 2. Print all response headers in the description:

foreach(var ik in (Tasks["test"] as Http).Response.Headers.Keys)
Response.Description += ik + ": " + (Tasks["test"] as Http).Response.Headers[ik.ToString()] + "\r\n";

Example 3. Print response body in description

var irr =  (Tasks["test"] as Http).Response.BodyAsText;
Response.Description += irr;

The information can be found in a device report under Description.

Please contact technical support for more details on usage.