Instance Methods
The methods documented in this section are instance methods and may be called from an instance of HttpCommand. In the documentation below, we will use the name instance to represent an instance of HttpCommand.
Run
Run "runs" the HTTP request defined by the instance's settings. Run is called internally by the shared "shortcut" methods Get, GetJSON, and Do.
| Syntax | result←instance.Run |
result |
result depends on the RequestOnly setting.If RequestOnly=1, Run will return, if possible, the HTTP request that would be sent if RequestOnly was set to 0. If HttpCommand cannot form a proper HTTP request, Run will return a result namespace with pertinent information.If RequestOnly=0, Run will return a result namespace containing the result of attempting to build and send the HTTP request specified by the instance's settings. |
| Examples | instance←HttpCommand.New ''There isn't sufficient information for HttpCommand to build a proper HTTP request.⊢result ← instance.RunNow, there's enough information to form a proper HTTP request. ⊢result ← instance.Run |
Show
Returns the HTTP request that HttpCommand would send when Run is executed and RequestOnly is 0. Show is equivalent to setting RequestOnly to 1 and running Run.
| Syntax | r←instance.Show |
r |
The result r is a character vector representing a properly formatted HTTP request if such a request can be formatted from the instance's settings.If the request cannot be formatted, r is a namespace containing a non-0 return code, rc, and an explanatory message, msg. |
| Example | instance ← HttpCommand.New 'get' 'dyalog.com' |
Config
Config returns the current state of all HttpCommand settings.
| Syntax | r←instance.Config |
r |
A 2-column matrix where[;1]contains the setting names[;2]contains the corresponding setting values |
| Example | instance←HttpCommand.New 'get' 'dyalog.com' |
Init
Init initializes Conga, Dyalog's TCP/IP utility library. Normally, HttpCommand will initialize Conga when Run is first called. Init is intended to be used when the user wants to "tweak" Conga prior to Run being executed. It's very unlikely that you'll ever need to use Init.
| Syntax | r←instance.Init |
r |
a 2-element vector of
|
| Example | instance←HttpCommand.New '' |
Header-related Methods
There are two sets of headers associated with an HTTP request - the request headers and the response headers. The methods described here deal with request headers.
HttpCommand's request headers are stored in the Headers setting which is a 2-column matrix of name/value pairs. Header names are case-insensitive; header values are not. While you can manipulate the Headers array directly, HttpCommand has three methods to manage Headers that accommodate the case-insensitive nature of header names.
By default, HttpCommand will automatically generate several request headers if you haven't specified values for them. See SuppressHeaders for the list of these headers. To suppress the generation of specific headers, you can set its value to ''.
Note: The examples below were run using ]boxing on.
AddHeader
AddHeader will add a header if a user-defined header with that name does not already exist. Use SetHeader to set a header regardless if one with the same name already exists.
| Syntax | {hdrs}←name instance.AddHeader value |
value |
the value for the header |
name |
the name for the header |
hdrs |
the updated matrix of user-specified headers |
| Example | instance←HttpCommand.New '' AddHeader will not replace an existing header with the same case-insensitive name.'my-header' instance.AddHeader 'Daffy Duck'Setting the value of an HttpCommand-generated header that to '' will suppress that header from being sent in the request.'accept-encoding' instance.SetHeader '' |
SetHeader
SetHeader will set a header, replacing one of the same name if it already exists.
| Syntax | {hdrs}←name instance.SetHeader value |
value |
the value for the header |
name |
the name for the header |
hdrs |
the updated matrix of user-specified headers |
| Example | instance←HttpCommand.New '' SetHeader will replace an existing header with the same case-insensitive name⊢'my-header' instance.SetHeader 'Daffy Duck'Setting the value of an HttpCommand-generated header that to '' will suppress that header from being sent in the request.'accept-encoding' instance.SetHeader '' |
RemoveHeader
RemoveHeader removes a user-specified header. If the header does not exist, RemoveHeader has no effect. RemoveHeader does not affect the HttpCommand-generated headers.
| Syntax | {hdrs}←instance.RemoveHeader name |
name |
the case-insensitive name of the header to remove</td |
hdrs |
the updated matrix of user-specified headers |
| Example | 'My-Header' instance.SetHeader 'Daffy Duck' |