HTTPRequest


 

HTTPRequest>URL,[LocalFilename],Method,[POST_Data],Result_Variable[,ProxyServer,ProxyPort,ProxyUsername,ProxyPassword]

 

Not supported in Macro Scheduler Lite.

 

Performs an HTTP request. E.g. fetch a web page, submit a form post, or interact with an API.


 

URL

URL of document to retrieve. Can be HTTP or HTTPS. e.g. https://www.google.com/
 

LocalFileName

Optional (may be left blank) - local file to save response to.
 

Method

GET, POST, PUT, PATCH or DELETE
 

Post_Data

Data to Post to URL if using POST method. Use name=value pairs separated by '&' or for JSON first set HTTP_POSTJSON to 1.  See examples below.
 

Result_Variable

Stores result of operation.  If LocalFileName is not specified and the operation is successful this will contain the HTML returned.  If LocalFileName was specified and the data was successfully written to the file Result_Variable will be blank.  Otherwise it will contain an error message.
 

ProxyServer
 

Optional - if using a proxy server set this to domain or IP address of proxy server.
 

ProxyPort
 

 Optional - if using a proxy server set to port number of proxy server.
 

ProxyUsername
 

Optional - if using a proxy server that needs a username.
 

ProxyPassword
 

Optional - if using a proxy server that needs a password.

Posting Files

To post files use the HTTP_POSTFILES variable. HTTP_POSTFILES takes name=value pairs separated by '&' in the same format as Post_Data but for 'file' parameters.  Post_Data can be empty if only files are being posted. See examples below.

Custom Headers

Let>HTTP_CUSTOM_HEADERS=Authorization: bearer SECRET_PASSWORD%CRLF%Accept: application/json

Timeouts

By default there is no timeout for the HTTPRequest command and requests will wait indefinitely if the server fails to respond. To change this set the HTTP_TIMEOUT value to the number of seconds to wait.

Redirects

By default HTTPRequest will automatically resolve redirects. To disable this behaviour set HTTP_REDIRECTS to 0.

Basic Authentication

For basic authentication where a username and password is required by the server before the request will complete put the username and password in the URL using the following format: http://username:[email protected]/etc.etc

SSL

For SSL (https) connections ensure the URL starts with "https" or set HTTP_SSL to 1. To use SSL the OpenSSL binaries are required. Version 1.0.2q is installed with Macro Scheduler.

 

If you need to explicitly set the TLS version to use with SSL set TLS_VER to one of the following values:

 

1

TLS v1.0

11

TLS v1.1

12

TLS v1.2

Other option variables:

- Set the HTTP_CHARSET variable to a character encoding name to override the default character set

- Set the HTTP_USERAGENT variable to override the user agent string that HTTPRequest sends

 

Abbreviation : HTT 

Examples

The following line does a simple GET request and saves the resulting HTML to a variable called HTMLResponse:

 

HTTPRequest>https://www.mjtnet.com,,GET,,HTMLResponse


 

 

The following line does the same thing but saves the output to a file instead of a variable:

 

HTTPRequest>https://www.mjtnet.com,d:\HTML\mjtnet.html,GET,,HTMLResponse

 


 

This demonstrates a POST operation, sending name=value pairs to the page:

 

Let>[email protected]&name=Joe Bloggs

HTTPRequest>https://www.someplace.com/someform.html,,POST,PostData,HTMLResponse

 


 

Posting JSON:

 

Let>HTTP_POSTJSON=1

Let>json_data= { "name":"fred","age":36 }

HTTPRequst>https://api.server.io/userInfo,,POST,json_data,HTMLResponse

 


 

Posting files:

 

Let>HTTP_POSTFILES=upload1=c:\stuff\logo.gif

HTTPRequest>http://www.someplace.com/form.html,,POST,,HTMLResponse