HTTP script action

HTTP action

Use the HTTP action to add specific HTTP requests to your script. Use this action to add a GET, POST, PUT, DELETE, or HEAD method to a step. You can also add headers that will apply to all requests created in this action.

Additionally, you can define a JavaScript function that executes when the reply to an HTTP request is received. This enables you to capture content or take actions based on the response. Note that this is available in Firefox only. The Response API is described below.

The Recorder sometimes adds HTTP actions during recording for traffic generated from plug-ins such as Flash and Silverlight.

When you create a script for a native application, the activity is recorded as HTTP actions, with a Wait action following each HTTP action.

Add an HTTP action

  1. Place the mouse cursor in the timeline where you want to add a HTTP request.

  2. Select the add icon that appears to display the list of actions.

  3. Select HTTP.
    Select HTTP action

Add an HTTP request

  1. Select the HTTP Requests tab if it is not already selected.
    HTTP requests tab

  2. Click the addicon Add row icon located at the far right of the page. A row is added for creating the HTTP request.
    Add an HTTP request

  3. From the list, select the method type.
    GET is selected by default. The other choices are DELETE, HEAD, POST, and PUT.
    Select method type

  4. Enter the URL in the field.

  5. Define the method, as described below.

  • GET or Head – Specify headers.
  • POST, DELETE, or PUT – Specify the body and headers.

After you define method details, the More link background changes from gray to green:
More link - highlighted

Add headers that apply to all requests

  1. Select the Headers tab for the HTTP action.
    Headers tab

  2. Click the add icon Add row icon at the right side of the page to display fields for defining the header.
    Define header

  3. Enter the name and value.

  4. Repeat steps 2 and 3 as needed to create additional headers.

Add reply handling

  1. Select the HTTP Requests tab for the HTTP action.

  2. Select More located next to an HTTP request.

  3. Select the Reply Handler tab and enter your JavaScript. See below for an example.
    Reply handler tab

Response API

response – reference the current reply object

Properties

  • status – The status code from the result (for example 200, 404, and so on).
  • headerNames – Returns an array of the header names that exist in the reply.
  • content – The reply content as a string.
  • contentBytes – The reply content as a byte array.

All response properties are read-only

Method

  • getHeader(name) – Returns the value of the header. If it does not exist, it will return null. If there are multiple headers with the same name, it will return a string with a list separated by ", " (COMMA + SPACE)

Example code for a reply handler

if (response.status == '200'){
    body = response.content;
    orderId = body.match(/orderId\=([0-9]+)/)[1];
}

The reply handler returns the value of the header. If it does not exist, it will return null. If there are multiple headers with the same name, it will return a string with a list in which items are separated by a comma followed by a space.