http

The http statement initiates an HTTP session using any settings previously configured using the set statement. It can also be used for querying response headers.

Syntax

httpmethod url

http dump_headers

http get_headerheaderNameasvarName

Details

Executing an HTTP request

The http statement performs an HTTP request against the server and resource specified in the url paramater. Any http-related settings previously configured using set will be applied to the request.

The method argument determines the HTTP method to use for the request and must be one of GET, PUT, POST or DELETE.

The url argument must start with either http: or https:. If https: is used then SSL will be used for the request.

The url argument must also contain a valid IP address or hostname. Optionally, it may also contain a port number (preceded by a colon and appended to the IP address or hostname) and a resource.

The following defaults apply if no port or resource is specified:

Field

Default

port

80 if using http 443 if using https

resource

/

The format of the http statement is identical when used in conjunction with the buffer statement.

Querying response headers

To dump a list of all the response headers returned by the server in the most recent session use the statement:

http dump_headers

This will render a list of the headers to standard output, and is useful when implementing and debugging USE scripts. The intention of this statement is to provide a tool to assist in script development, and as such it would normally be removed or suppressed with a debug mode switch in production environments.

To retrieve the value of a specific header, use the statement:

http get_headerheaderNameasvarName

This will set the variable varName to be the value of the header headerName.

If headerName was not found in the response, then a warning will be written to the log-file. In this case varName will not be created but if it already exists then its original value will be unmodified.

Examples

Example 1

# A simple request using the default port and no SSL
set http_savefile "/extracted/http/customers.json"
http GET "http://localhost/v1/customers"

# A more complex request requiring setup and a custom port
clear http_headers
set http_header "Accept: application/json"
set http_header "Authorization: FFDC-4567-AE53-1234"    
set http_savefile "extracted/http/customers.json"
buffer customers = http GET "https://demo.server.com:4444/v1/customers"

Example 2

The following shows the process of retrieving a header. The output of:

buffer temp = http GET https://www.google.com
http dump_headers
http get_header Date as responseDate
print The Date header from google.com was: ${responseDate}

Takes the following form:

Last response headers:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Mon, 26 Mar 2018 13:50:39 GMT
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1
Expires: -1
Accept-Ranges: none
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
Set-Cookie: 1P_JAR=2018-03-26-13; expires=Wed, 25-Apr-2018 13:50:39 GMT; path=/; domain=.google.co.uk
Set-Cookie: [redacted]; expires=Tue, 25-Sep-2018 13:50:39 GMT; path=/; domain=.google.co.uk; HttpOnly
Vary: Accept-Encoding
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alt-Svc: hq=":443"; ma=2592000; quic=51303432; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="42,41,39,35"

The Date header from google.com was: Mon, 26 Mar 2018 13:50:39 GMT

Last updated