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.

Component Properties

Property Name Description
HTTP Method GET, POST, HEAD, PUT, DELETE
URL The URL to send the HTTP request to
Content-Type The Content-Type of the HTTP header
Authentication Method None, Basic Authentication, Basic/Digest Authentication, Bearer Authentication. When specifying the value in cp.Authorization, use one of "(none)", "prebasic", "basicdigest", or "bearer"
Username Basic authentication username
Password Basic authentication password
Token Bearer token
Advanced Features Use detailed configuration features
Allow Invalid SSL/TLS Server Certificates A flag that determines whether to continue processing even if the SSL/TLS server certificate is invalid during HTTPS communication
Retry Count The number of retries when a connection to the server cannot be established, an HTTP response cannot be received, or if the HTTP response status is 500 or higher, 408, or 429
Retry Interval The interval value before the next retry when a retry is performed
Timeout HTTP request-response timeout value
Proxy URL URL when using a proxy
Proxy Username Username when using a proxy
Proxy Password Password when using a proxy
Request/Response Dump None, No Body, With Body

※ The “Allow Invalid SSL/TLS Server Certificates” setting can also be controlled programmatically by setting cp.InsecureSkipVerify to true in PreMapping.

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

Content-Type Property

The HTTPRequest component creates and sends the following Body when the input Payload is of JSON Object type, and the Content-Type property is either (application/x-www-form-urlencoded) or (multipart/form-data).

Input Payload

{
    "key1": "value1",
    "key2": "value2"
}


Body when (application/x-www-form-urlencoded) is used

POST ....
Content-Type: application/x-www-form-urlencoded

key1=value1&key2=value2


Body when (multipart/form-data) is used

POST ....
Content-Type: multipart/form-data; boundary=XXXXX

--XXXXX
Content-Disposition: form-data; name="key1"

value1
--XXXXX
Content-Disposition: form-data; name="key2"

value2
--XXXXX--

p.

How to specify file transmission using multipart/form-data

Input Payload

{
    "name": "<key>",
    "filename": "<path>",
    "filenameOfContentDisposition": "<filename>"
    "contentType": "image/jpeg"
}

name: Specifies the name parameter of the Content-Disposition header. If a key exists, it is used automatically, but it can be overridden by specifying it. If the parent is an array or no key exists, name is required.
key: When a file is not specified, the Body is specified using key. It is specified as a string type. Other types will also be automatically converted to strings and used. JSON Object types are also converted to strings.
filename: Specifies the Body as a file. The file path should be specified as either a relative or absolute path from the data directory. Multiple files can be specified by separating them with semicolons, and wildcards can also be used. When multiple files are specified, each file will be treated as a separate part. This is useful when using multiple file selections in a form.
contentType: Specifies the Content-Type header when a filename is specified. If not specified, it is automatically determined from the file extension.
filenameOfContentDisposition: Specifies the filename parameter of the Content-Disposition header. If not specified, only the filename part without the directory path is used.

Using multiple file selection in a form

For example, if a form specifies multiple file selections, the browser opens a dialog that allows selecting multiple files. If two files, sample1.txt and sample2.txt, are selected, the browser sends the following multipart/form-data in the POST request.

<form>
<input type="file" name="userfile" multiple="multiple"/>
<button type="submit" ...>Submit</button>
</form>
------XXXXX
Content-Disposition: form-data; name="userfile"; filename="sample1.txt"
Content-Type: text/plain

abc
------XXXXX
Content-Disposition: form-data; name="userfile"; filename="sample2.txt"
Content-Type: text/plain

def
------XXXXX--

The same name parameter is used for Content-Disposition.
Similarly, when multiple files are specified in the HTTPRequest component using wildcards, multiple parts with the same name parameter are created.
Alternatively, if different names are specified for each input in the form, the browser generates the following multipart/form-data:

<form>
<input name="userfile1" type="file" />
<input name="userfile2" type="file" />
<button type="submit" ...>Submit</button>
</form>
------XXXXX
Content-Disposition: form-data; name="userfile1"; filename="sample1.txt"
Content-Type: text/plain

abc
------XXXXX
Content-Disposition: form-data; name="userfile2"; filename="sample2.txt"
Content-Type: text/plain

def
------XXXXX--


The HTTPRequest component does not support wildcards, but it can generate the same multipart/form-data structure as this form.
Use it according to the server (API) specifications.

Example configurations for file transmission using multipart/form-data

Example of sending a photo to Telegram (including a caption)
https://telegram-bot-sdk.readme.io/reference/sendphoto

 {
    "chat_id": "-100XXXXX",
    "photo": {"filename": "sample.jpg"},
    "caption": "caption"
}

p.

Example of uploading a file to Box

(The Box API requires the multipart parts to be in the order of attributes → file, so they are specified as an array)
https://ja.developer.box.com/reference/post-files-content/

 [
    {
  	    "name": "attributes",
  	    "value": {
  	        "name": "sample.jpg",
  	        "parent": {"id": "0"}
        }
    },
    {
        "name": "file",
        "filename": "sample.jpg"
    }
]

p.

Example of sending a file to ConvertAPI

https://www.convertapi.com/a/api/xlsx-to-pdf#snippet=curl

 {
    "StoreFile": "true",
    "File": {"filename": "sample.xlsx"}
}

p.

Example of retrieving multiple files in PHP using $_FILES on the server side

(Appending [] to the name allows PHP to handle multiple files. Files can be specified using wildcards or separated by semicolons)
https://www.php.net/manual/ja/reserved.variables.files.php

 {
  "file[]": {"filename": "*.jpg"}
}

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

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.