TestPlan createHTTPRequest
Document

createHTTPRequest

by Group Public on Wednesday June 09 2010 @ 09:10:25 (1/1 Points)

API ↪Reference ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It

createHTTPRequest allows creation of an arbitrary HTTP Request object. This is used in cases where simply specifying a URL or using one of the standard functions is not sufficient. This often arises when trying to use a REST API or to test very specific requests.

set %Request% as createHTTPRequest with
  %Path% http://google.com/
  %Method% GET
  %Params% with
    %q% TestPlan
  end
end
GetRequest %Request%
DumpCurrentResponse STDOUT

Request Settings

Path

Path specifies the URI for the request. Since this function creates HTTP requests you should use only http or https. If you specify a relative URI (one without a scheme) it will be appended to Web.BaseURL to form the URL.

Charset

Allows you to specify the character set used to send the request. Any content will be converted to this character set when sending, so be sure to use one which covers all used characters.

Method

Which HTTP method is to be used. The most common ones are GET and POST.

Encoding

Specifies how to encode the parameters used for this request. This tends to become the Content-Type of the resulting HTTP request.

  • application/x-www-form-urlencoded - the default
  • multipart/form-data
  • multipart/related

TransferEncoding

Allows you to specify which TransferEncoding should be used.

  • default - the default, whatever is appropriate
  • none - forcibly use the Content-Length header instead of Transfer-Encoding
  • chunked - use chunked encoding

Parameters

To specify simple request parameters you use the Params map. This will be converted based on your choice of Method and Encoding.

set %Request% as createHTTPRequest with
  %Path% Register.jsp
  %Params% with
    %name% Johnny
    %email% john.e@example.com
    %terms% 1
  end
end

For GET requests these will be added to the URL whereas for POST requests these will be encoded in the body.

Extra Headers

If you need to specify additional HTTP headers in the request then use the Headers map. This is meant for custom headers, not overriding or setting standard headers. If you do overlap with automatically set headers the behaviour is undefined.

set %Request% as createHTTPRequest with
  %Path% mypath.php
  %Headers% with
    %X-Action% execute
  end
end

Custom Multipart Requests

In some situations you may wish to hand-construct the multipart request. Here you can use the Parts map to generate those parts. The name entry in this map is significant, as all parts have names in MIME.

%Parts% with
  %Part1% with
    %Content% Hello Part
    %Headers% with
      %Content-Type% text/plain
    end
  end
  %Part2% with
    %Content% <b>Goodbye Part</b>
    %Headers% with
      %Content-Type% text/html
    end
  end
end

The Content of a part specifies the content for that part. It will be converted to any specified Charset -- thus only textual content is supported with this parameter.

The Headers of a part specify the headers for the part. You should include at least Content-Type.

Encoding

If using custom multipart messages you should set the Encoding to an appropriate multipart type like multipart/related.

Explicit Body Content

In some cases it may be desired to completely override the generated body of the HTTP request. To do so you specify the ContentType and then one of Content or BinaryContent.

Do not specify any other parts, parameters, or Encoding, when using this mode.

call unit.web.HTTPGetRequest with
  %Path% %URL%
  %Method% POST
  
  %ContentType% application/x-custom
  %Content% asdf/323mn/3njdk/234
end
© 2008-2010 edA-qa mort-ora-y
Using Persephone and TestPlan
Tag: