|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > HTP. - Command > HTP. - HTTP Operations |
SPR Script Language
HTP.SetDef
Sets one or more default parameters for the HTP library.
Intention
The HTP.SetDef command is a convenient way to configure the behavior of the HTP library for subsequent commands like HTP.ReqShort. You can set multiple parameters at once using key=value pairs. This is the primary method for setting the default API key, timeouts, proxy settings, and other global options that will be used by other HTP commands unless they are explicitly overridden in the command itself.
It’s like adjusting the settings of your robot’s web browser—HTP.SetDef prepares the library for all future requests, so you don't have to specify common parameters every time.
Syntax
HTP.SetDef|Key1=Value1[|Key2=Value2|...]
Parameter Explanation
P1..Pn - Key=Value - (String, Required)
One or more key-value pairs separated by pipes (|). The key is case-insensitive. The value can be a literal or an SPR variable (e.g., APIKEY=$$KEY). The following keys are supported:
APIKEY - Sets the default Bearer token for authorization.
TIMEOUT - Sets all timeout values (resolve, connect, send, receive) to the same value in milliseconds.
RESOLVE - Sets the DNS resolve timeout in milliseconds.
CONNECT - Sets the connection timeout in milliseconds.
SEND - Sets the send timeout in milliseconds.
RECEIVE - Sets the receive timeout in milliseconds.
PROXYENABLE - Enable (1) or disable (0) the proxy.
PROXYNAME - The proxy server URL (e.g., "http://proxy:8080").
PROXYBYPASS - The proxy bypass list (e.g., "").
USERAGENT - Sets the default User-Agent by index (0-30).
DEBUG - Enable (1) or disable (0) verbose debug logging.
CLIPBOARD - Enable (1) or disable (0) auto-copying results to the clipboard.
FLAGS - Sets the default numeric request flags.
Examples
'***********************************
' HTP.SetDef - Sample 1: Configure for an API
'***********************************
VAR.$$KEY=sk-YourSecretKeyHere
HTP.SetDef|APIKEY=$$KEY|TIMEOUT=45000
' Now, HTP.ReqShort will automatically use this key and a 45-second timeout
VAR.$$URL=https://api.example.com/v1/data
HTP.ReqShort|GET|$$URL|||$$RES
MBX.Response:|$$RES
END.
'***********************************
' HTP.SetDef - Sample 2: Using a variable for the key=value pair
'***********************************
VAR.$$CFG=USERAGENT=5
HTP.SetDef|$$CFG
HTP.ReqShort|GET|https://httpbin.org/user-agent|||$$RES
PSJ.Parse|$$RES|$$H_1
PSJ.GetStr|$$H_1|user-agent|$$VAL
MBX.User Agent:|$$VAL
PSJ.Free|$$H_1
END.
Remarks
- This command is the recommended way to set persistent configurations for the HTP library within a script.
- Settings persist until they are changed by another HTP.SetDef call or a specific setter (e.g., HTP.SetTO).
- Passing a value of 0 for a timeout key (e.g., TIMEOUT=0) will reset it to the library's hardcoded default.
See also: