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 '' instance.RequestOnly←1 There isn't sufficient information for HttpCommand to build a proper HTTP request. ⊢result ← instance.Run
[rc: ¯1 | msg: No URL specified | HTTP Status: "" | ⍴Data: 0] instance.URL←'dyalog.com' Now, there's enough information to form a proper HTTP request. ⊢result ← instance.Run GET / HTTP/1.1
instance.RequestOnly←0 ⊢result ← instance.Run [rc: 0 | msg: | HTTP Status: 200 "OK" | ⍴Data: 23127]
|
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 | |
Example | instance ← HttpCommand.New 'get' 'dyalog.com' instance.Show GET / HTTP/1.1 Host: dyalog.com User-Agent: Dyalog-HttpCommand/5.0.3 Accept: */*
|
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' instance.Config Auth AuthType BufferSize 200000 Cert Command get CongaPath CongaRef CongaVersion ContentType Cookies Debug 0 Headers KeepAlive 1 LDRC not set MaxPayloadSize ¯1 MaxRedirections 10 OutFile Params Priority NORMAL:!CTYPE-OPENPGP PrivateKeyFile PublicCertFile RequestOnly 0 SSLFlags 32 SuppressHeaders 0 Timeout 10 TranslateData 0 URL dyalog.com WaitTime 5000 |
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 '' instance.CongaPath←'/doesnotexist' instance.Init ¯1 CongaPath "c:/doesnotexist/" does not exist
|
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.
Note: The examples below were run using ]boxing on
.
AddHeader
AddHeader
will add a header if a header with that name does not already exist. Use SetHeader
to set a header regardless if one with the same name already exists.
Syntax | name instance.AddHeader value |
value |
the value for the header |
name |
the name for the header |
Example | instance←HttpCommand.New '' 'My-Header' instance.AddHeader 'Drake Mallard' instance.Headers ┌─────────┬─────────────┐ │My-Header│Drake Mallard│ └─────────┴─────────────┘ AddHeader will not replace an existing header with the same case-insensitive name 'my-header' instance.AddHeader 'Daffy Duck' instance.Headers ┌─────────┬─────────────┐ │My-Header│Drake Mallard│ └─────────┴─────────────┘ |
SetHeader
SetHeader
will set a header, replacing one of the same name if it already exists.
Syntax | name instance.SetHeader value |
value |
the value for the header |
name |
the name for the header |
Example | instance←HttpCommand.New '' 'My-Header' instance.SetHeader 'Drake Mallard' instance.Headers ┌─────────┬─────────────┐ │My-Header│Drake Mallard│ └─────────┴─────────────┘ SetHeader will replace an existing header with the same case-insensitive name 'my-header' instance.SetHeader 'Daffy Duck' instance.Headers ┌─────────┬──────────┐ │My-Header│Daffy Duck│ └─────────┴──────────┘
|
RemoveHeader
RemoveHeader
removes a header. If the header does not exist, RemoveHeader
has no effect.
Syntax | instance.RemoveHeader name |
name |
the case-insensitive name of the header to remove |
Example | 'My-Header' instance.SetHeader 'Daffy Duck'
'another' instance.SetHeader 'some value'
instance.Headers ┌─────────┬──────────┐ │My-Header│Daffy Duck│ ├─────────┼──────────┤ │another │some value│ └─────────┴──────────┘
instance.RemoveHeader 'my-header' instance.Headers ┌───────┬──────────┐ │another│some value│ └───────┴──────────┘ |