Webtest WebTest GitHub Home

Core Type httpHeader

Description

The httpHeader step appends new or replaces existing HTTP header fields sent during an invoke step.

HTTP headers define the operating parameters of an HTTP transaction and are specified as a single name-value pair for each httpHeader element used. For example:
<invoke url="http://foo.com/api/v2/bar/">
  <httpHeader name="Acceptvalue="text/plain" />
  <httpHeader name="Authorizationvalue="Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" />
</invoke>
name
Required? yes
The name of the HTTP header as defined by the HTTP spec., e.g. User-Agent, Accept-Language or Cookie.
value
Required? yes
The header value. Range and format are restricted by the HTTP spec., e.g. Mozilla/4.0, de-ch or cookieName=cookieValue

Details

Some HTTP headers such as Content-Type are built into the invoke step. Use the invoke version when it exists.

invoke with CSRF headers
<invoke description="Get default pageurl="/service/index.jsp" />

<storeCookie name="JSESSIONIDproperty="csrf.session" />
<storeXPath description="Extract CSRF Token"
            xpath="//meta[@name='_csrf']/@content"
            property="csrf.token" />
<storeXPath description="Extract HTTP Header for CSRF"
            xpath="//meta[@name='_csrf_header']/@content"
            property="csrf.header" />

<invoke url="/service?${query.params}
        method="POST
        contentType="application/json"
        content='${content}'>
  <httpHeader name="${csrf.header}value="${csrf.token}" />
  <httpHeader name="Cookievalue="JSESSIONID=${csrf.session}" />
</invoke>

Usage

invoke.