Scripting Parameters and Methods - HTTP Requests
There are a number of parameters and methods pertinent to HTTP objects that are available when using HTTP objects to make an HTTP Request in a Custom Script within an Action, or in script within a Map event.
Script Parameters/Properties For Requests
Parameter/Property | Description |
---|---|
HTTP.Connection | The name of the HTTP Connection to be used, as a string. Example: HTTP . Connection := ‘NZ_Post’; |
HTTP.Header[name] | Array of header elements to send. Add name/value pairs as header elements to be sent with the connection, as strings. By default blank header values will not be sent. Example: HTTP . Header[ 'security-token' ] := 'itsasecret' ; HTTP . Header[ 'accept-type' ] := 'text/csv' ; |
HTTP.Param[name] | Array of parameters to send in the query string. Add name/value pairs as string parameters that will be used in the query string. By default, blank param header values will not be sent. Example: HTTP . Param[ 'q' ] := 'Waitakere' ; HTTP . Param[ 'likefrogs' ] := 'yes' ; HTTP . Param[ 'likefrogs' ] : = '' ; //makes previous param blank |
HTTP.QueryString | The connection’s query string as one input string. If set, this will override any param[] values that have been set. You may need to URLEncode() the values after the equal sign ( = ). A typical URL containing a query string could be https://example.co.nz/tutorials/what?name=blossom. When a server receives a request for such a page, it may run a program and pass in the query string name=blossom unchanged to the program. The question mark is used as a separator, and is not part of the query string. Example: HTTP . QueryString := 'q=Waitakere®ion=Auckland' ; HTTP . QueryString := 'name=' + URLEncode( 'Peter Peterson' ); |
HTTP.SendEmptyHeaders | A boolean flag to define whether empty headers should be sent. The default is False. Example: HTTP . SendEmptyHeaders := True ; //Empty header will be sent |
HTTP. EmptyParamRule | The flag that defines how empty parameters will be handled. Valid values are epExclude, epInclude, epIncludeAsFlag. Refer HTTP.EmptyParamRule: TFloEmptyHTTPParamRule Example: HTTP . EmptyParamRule = eqInclude; |
HTTP.ContentAsString | Allows you to assign a string value directly to the HTTP message body, When assigning a value in this way, the existing contents of the Content stream are entirely overwritten and replaced. This would be your first choice for sending a payload. Example: vReqJSON := TJSONObject . Create; vReqJSON[ 'NAME' ] := TJSONString . Create( 'Mo' ) as TJSONValue; vHTTPReqBodyStr := vReqJSON . ToJSON; HTTP . ContentAsString := vHTTPReqBodyStr; |
HTTP.ConnectionFID | Use the FID of the HTTP Connection to be used, rather than the name of the connection. Copy the FID by double-clicking on it. Example: // Rather then using ... HTTP.Connection := 'NZ Customs Rates' HTTP . ConnectionFID := '{D572D072-8E98-4086-A28C-A6E14EB2C747}' ; |
HTTP.Response | |
HTTP.KeepProtocol | |
HTTP.CookiesDisabled | |
HTTP.Port | The Port is found on the HTTP Connection to be used. However, this can be overridden by entering the Port programmatically, For instance, 443 is the HTTPS default value. Changing this Port value does not have any affect on the Protocol. Example: HTTP . Port := 441 ; |
HTTP.Protocol | A read-only setting. Example: |
HTTP.Path | The Path is found on the HTTP Connection to be used. However, this can be overridden by entering the Path programmatically, Example: HTTP . Path := 'buffers' ; Or, HTTP.Path := 'news/datafeeds/exchange' ; |
HTTP.ContentAsString |
Script Methods For Requests
Method | Description |
---|---|
HTTP.Open | AMethod is the HTTP method you are going to use such as GET, or POST, and aURL is the path of your request. Declaration: HTTP.Open(const aMethod: String; const aURL: String); Example: HTTP . Open(GET, 'api/amazing.asp' ); HTTP . Open(POST, 'somewhere/secretmessage.php' ); |
HTTP.Send | Once you have set the connection, opened the path, defined parameters, headers and content, call this method to send your request. Example: HTTP . Connection := 'NZ_Post' ; HTTP . Open( 'GET' , 'api/postcode/search.json' ); HTTP . Header[ 'AUTH-KEY' ] := 'secretkey' ; HTTP . QueryString := 'q=Waitakere®ion=Auckland' ; HTTP . Send; |
HTTP.Content.Write | This is an option for sending a payload via a stream. Define the message body being sent in a POST or PUT request. You can send a message body with other methods, like GET, but HTTP 1.1 says it will be ignored. The data argument is the data you are sending, and size is that size of that data in bytes. The usual supported methods of the HTTP.Content stream object may be used to write data to the content. Declaration: HTTP.Content.Write(const aData: String; const aSize: Integer); Example: data := 'My secret message' ; HTTP . Content . Write (data, Length(data)); |
HTTP.Content | A third option for sending a payload. You can assign a HTTP stream directly to the HTTP content. The stream will replace any existing content. Refer HTTP.Content:TStream Example: HTTP . content := stream; |