Make it possible to send Form-Data with HttpRequest-Node

This commit is contained in:
Jan Oberhauser 2019-10-16 12:26:47 +02:00
parent a0fd9b2065
commit ea6ec1aa6c

View file

@ -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 = {