Using the HTTP Request component, you can send an HTTP request to a specified URL.
The HTTP Request component executes the HTTP request with the input payload as the Body content of the HTTP request, depending on its properties, and writes the HTTP response Body to the output payload (cv.Payload
).
Body content in HTTP requests with Content-Type property
Content-Type Property | Content of the Body at the time of the HTTP request |
---|---|
None | The input payload executes the HTTP request without being set to the Body. |
Default | Automatically selects the Content-Type based on the type of the input payload. |
Character string type | Output characters with “text/plain; charset=utf-8”. |
JSON array, JSON object | The HTTP request is executed as “application/json”, marshalling the Payload as a byte string. |
Byte sequence | The HTTP request is executed with the string set to “application/octet-stream” as the Body. |
Other | The HTTP request is executed with the string set to “text/plain” as the body. |
application/x-www-form-urlencoded | The input payload is a JSON object type, for example in the Pre-Mapping: cv.Payload = {"key": "value", "otherkey": "othervalue"} (In this case, if data other than the JSON Object type is received as input, an error occurs.) |
multipart/form-data | The input payload is JSON Object type, and the key and the value are separated by multipart, and the Content-Type multipart/form-data is automatically attached to the boundary before the HTTP request is executed. (In this case, if data other than the JSON Object type is received as input, an error occurs.) |
Any other arbitrarily entered Content-Type | The Content-Type is left as it is and the output is a string of bytes of the input payload as the Body. |
Output Payload | Description |
---|---|
cv.Payload |
The output payload (cv.Payload ) stores the body of the HTTP response as a string of bytes. |
Properties
Name | Required | Description |
---|---|---|
Method | True | The HTTP Request Method |
URL | True | The endpoint URL |
Content-Type | True | The HTTP Header Content-Type |
Authorization | True | The authorization type. When specified by the value of cp.Authorization, it can be one of “(none)”, “prebasic”, “basicdigest”, or “bearer”. |
Username | False | Basic authentication username |
Password | False | Basic authentication password |
Token | False | The Bearer Token |
Timeout | True | HTTP Request Timeout (ms) |
HTTP Proxy | False | HTTP Proxy |
Proxy URL | False | URL when using a proxy |
Proxy Username | False | Username when using a proxy |
Proxy Password | False | Password when using a proxy |
Dump | True | Dump the request/response to the output log (actmgr... logfile in the Gravio HubKit log directory of your OS.) |
Component Variables
cv.Payload |
On input: request body, on output: response body. |
---|---|
cv.StatusCode |
Request result |
cv.Headers |
On output: response header will be stored in this component variable. To send custom request headers, please use component properties cp.Headers (see example below) |
cv.ContentLength |
Response content length |
Testing the HTTP Requests
We recommend a free service called requestbin.com to create a testing endpoint and to send your HTTP requests to. In their live dashboard you can see the incoming requests. (Note, the above link creates a public requestbin. For private requestbins, you will need an account).
If you enable the “debug” flag on the top left of the component box, you will find the variables in the log. There you can also see what the variable scopes (here tv.
) and names (for example Data
) are. These you can then refer to inside your JSON string in the cv.Payload
:
Here is a JSON example including an MD5 checksum you can use as template:
{
"AreaName": tv.AreaName,
"LayerName": tv.LayerName,
"KindName": tv.KindName,
"PhysicalDeviceName": tv.PhysicalDeviceName,
"PhysicalDeviceId": tv.PhysicalDeviceId,
"DataId": tv.DataId,
"Timestamp": ToInt(tv.Timestamp),
"Data":tv.Data,
"Checksum":MD5(tv.AreaName+tv.Data+tv.KindName+tv.PhysicalDeviceName+tv.PhysicalDeviceId+tv.DataId+ToInt(tv.Timestamp)+tv.LayerName+"SECRETSALT")
}
Overriding or Extending Header Information
You can add or override existing Header
information by creating a PreMapping
using this this JSON
syntax:
cp.Headers
= {"X-Header-1": "abc; def", "X-Header-2": ap.Timeout/1000, "X-Header-3": true, "X-Header-4": cp.URL, "Accept", "application/json", "User-Agent", "fugahoge browser"}
For example, Databox, a visualisation software requires certain headers. They can be set as follows:
Using a JSON HTTP Response Body in a Subsequent HTTP Request
You can take the JSON response from a HTTP request and use JSONPath() to extract a specific attribute of the reply.
If you want to use the data in a subsequent component, e.g. a HTTP request post data, it could look like this:
Need more help with this?
Join our slack community for help