From ea6ec1aa6c91076ee46f83b14dff40295a89ceba Mon Sep 17 00:00:00 2001 From: Jan Oberhauser <jan.oberhauser@gmail.com> Date: Wed, 16 Oct 2019 12:26:47 +0200 Subject: [PATCH] :sparkles: Make it possible to send Form-Data with HttpRequest-Node --- packages/nodes-base/nodes/HttpRequest.node.ts | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/HttpRequest.node.ts b/packages/nodes-base/nodes/HttpRequest.node.ts index 2ba1c70e3b..0e087fd883 100644 --- a/packages/nodes-base/nodes/HttpRequest.node.ts +++ b/packages/nodes-base/nodes/HttpRequest.node.ts @@ -187,7 +187,6 @@ export class HttpRequest implements INodeType { 'file', ], }, - }, description: 'Name of the binary property to which to<br />write the data of the read file.', }, @@ -207,6 +206,35 @@ export class HttpRequest implements INodeType { placeholder: 'Add Option', default: {}, options: [ + { + displayName: 'Body Content Type', + name: 'bodyContentType', + type: 'options', + displayOptions: { + show: { + '/requestMethod': [ + 'POST', + 'PUT', + ], + }, + }, + options: [ + { + name: 'JSON', + value: 'json' + }, + { + name: 'Form-Data Multipart', + value: 'multipart-form-data' + }, + { + name: 'Form Urlencoded', + value: 'form-urlencoded' + }, + ], + default: 'json', + description: 'Content-Type to use to send body parameters.', + }, { displayName: 'Full Response', name: 'fullResponse', @@ -546,6 +574,17 @@ export class HttpRequest implements INodeType { } } + // Change the way data get send in case a different content-type than JSON got selected + if (['POST', 'PUT'].includes(requestMethod)) { + if (options.bodyContentType === 'multipart-form-data') { + requestOptions.formData = requestOptions.body; + delete requestOptions.body; + } else if (options.bodyContentType === 'form-urlencoded') { + requestOptions.form = requestOptions.body; + delete requestOptions.body; + } + } + // Add credentials if any are set if (httpBasicAuth !== undefined) { requestOptions.auth = {