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="Accept" value="text/plain" />
<httpHeader name="Authorization" value="Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" />
</invoke>
<httpHeader name="Accept" value="text/plain" />
<httpHeader name="Authorization" value="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 page" url="/service/index.jsp" />
<storeCookie name="JSESSIONID" property="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="Cookie" value="JSESSIONID=${csrf.session}" />
</invoke>
<storeCookie name="JSESSIONID" property="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="Cookie" value="JSESSIONID=${csrf.session}" />
</invoke>