|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > HTP. - Command > !HTP-General - General HTTP operations and utilities > !Request-Management - Commands for preparing, executing, and inspecting HTTP requests > HTP. - HTTP Operations |
SPR Script Language
HTP.Request
Performs a full HTTP request with detailed configuration options.
Intention
The HTP.Request command provides complete control over an HTTP request. It is the ideal choice for complex interactions that require custom headers, specific request flags (like disabling SSL checks), or a non-default User-Agent. Unlike the simpler HTP.ReqShort, this command allows every aspect of the request to be defined explicitly in its parameters.
The command returns the raw response body (un-decoded bytes) and the final HTTP status code on the top-of-stack (TOS).
Syntax
HTP.Request|$$RTP|$$URL[|$$DAT|$$HED|$$FLG|$$UAG|$$RET]
Parameter Explanation
P1 - $$RTP - (Variable, String, Required)
The HTTP request type (e.g., "GET", "POST", "PUT", "DELETE", "HEAD", "PATCH").
P2 - $$URL - (Variable, String, Required)
The full target URL.
P3 - $$DAT - (Variable, String, Optional)
The payload data for the request body. If omitted or empty, no body is sent.
P4 - $$HED - (Variable, String, Optional)
A string of custom headers, with pairs separated by "*" and key/value separated by "=". Example: "Content-Type=text/plain*X-Custom-ID=123".
P5 - $$FLG - (Variable, numeric, Optional)
Numeric flags to modify request behavior. Valid values are:
2 - Headers Only (uses HEAD method)
4 - No Redirect
8 - No SSL Check (ignore certificate errors)
32 - Debug Mode
P6 - $$UAG - (Variable, numeric, Optional)
A number from 0 to 30 to select a specific User-Agent string. If omitted or -1, the global default is used. See HTP.GetUA.
P7 - $$RET - (Variable, String, Optional)
The variable to store the raw response body. If omitted, the response is not stored.
Examples
'***********************************
' HTP.Request - Sample 1: POST to local AI with custom headers
'***********************************
VAR.$$URL=http://localhost:1234/v1/chat/completions
VAR.$$HED=Content-Type=application/json*Authorization=Bearer not-needed
VAR.$$DAT={"model": "local-model", "messages": [{"role": "user", "content": "Hello!"}]}
HTP.Request|POST|$$URL|$$DAT|$$HED|0|-1|$$RES
JIV.$$TOS!200|Lab_failed
HTP.FromUTF8|$$RES|$$VAL
MBX.Response:|$$VAL
END.
'***********************************
' HTP.Request - Sample 2: GET with SSL check disabled
'***********************************
VAR.$$URL=https://self-signed.badssl.com/
VAR.$$FLG=8
HTP.Request|GET|$$URL|||$$FLG|-1|$$RES
JIV.$$TOS!200|Lab_failed
MBX.Success:|Successfully connected to a site with a bad SSL certificate.
END.
Remarks
- This command returns the HTTP Status Code on the top-of-stack ($$TOS). A value of 0 indicates a transport-level error. Check HTP.GetErr for details.
- The response body returned in $$RET is the raw, un-decoded byte string from the server. Use HTP.FromUTF8 or HTP.FixEncoding to decode it.
See also: