Httprequest
Node Documentation
Sends HTTP requests and returns the response.
Inputs
Outputs
Details
When configured within the node, the URL property can contain mustache-style tags. These allow the url to be constructed using values of the incoming message. For example, if the url is set to
example.com/{{{topic}}}
, it will have the value of msg.topic
automatically inserted. Using {{{...}}} prevents mustache from escaping characters like / & etc.
The node can optionally automatically encode msg.payload
as query string parameters for a GET request, in which case msg.payload
has to be an object.
Note: If running behind a proxy, the standard http_proxy=...
environment variable should be set and Node-RED restarted, or use Proxy Configuration. If Proxy Configuration was set, the configuration take precedence over environment variable.
Using multiple HTTP Request nodes
In order to use more than one of these nodes in the same flow, care must be taken with the msg.headers
property. The first node will set this property with the response headers. The next node will then use those headers for its request - this is not usually the right thing to do. If msg.headers
property is left unchanged between nodes, it will be ignored by the second node. To set custom headers, msg.headers
should first be deleted or reset to an empty object: {}
.
Cookie handling
The cookies
property passed to the node must be an object of name/value pairs. The value can be either a string to set the value of the cookie or it can be an object with a single value
property.
Any cookies returned by the request are passed back under the responseCookies
property.
Content type handling
If msg.payload
is an Object, the node will automatically set the content type of the request to application/json
and encode the body as such.
To encode the request as form data, msg.headers["content-type"]
should be set to application/x-www-form-urlencoded
.
File Upload
To perform a file upload, msg.headers["content-type"]
should be set to multipart/form-data
and the msg.payload
passed to the node must be an object with the following structure:
{
"KEY": {
"value": FILE_CONTENTS,
"options": {
"filename": "FILENAME"
}
}
}
The values of KEY
, FILE_CONTENTS
and FILENAME
should be set to the appropriate values.