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
http
method url
http dump_headers
http get_header
headerName
as
varName
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 |
|
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_header
headerName
as
varName
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
Example 2
The following shows the process of retrieving a header. The output of:
Takes the following form:
Last updated