added ability to post raw/string/xml

This commit is contained in:
Leo 2019-11-02 10:12:59 +01:00
parent 91498b4573
commit 644b5455c9

View file

@ -196,11 +196,11 @@ export class HttpRequest implements INodeType {
},
{
displayName: 'JSON Parameters',
displayName: 'JSON/RAW Parameters',
name: 'jsonParameters',
type: 'boolean',
default: false,
description: 'If the query and/or body parameter should be set via the UI or raw as JSON',
description: 'If the query and/or body parameter should be set via the value-key pair UI or JSON/RAW',
},
{
@ -228,6 +228,10 @@ export class HttpRequest implements INodeType {
name: 'JSON',
value: 'json'
},
{
name: 'RAW/Custom',
value: 'raw'
},
{
name: 'Form-Data Multipart',
value: 'multipart-form-data'
@ -240,6 +244,24 @@ export class HttpRequest implements INodeType {
default: 'json',
description: 'Content-Type to use to send body parameters.',
},
{
displayName: 'MIME Type',
name: 'bodyContentCustomMIMEType',
type: 'string',
default: '',
placeholder: 'text/xml',
description: 'Specify the mime type for raw/custom body type',
required: false,
displayOptions: {
show: {
'/requestMethod': [
'PATCH',
'POST',
'PUT',
],
},
},
},
{
displayName: 'Full Response',
name: 'fullResponse',
@ -357,7 +379,7 @@ export class HttpRequest implements INodeType {
},
},
default: '',
description: 'Body parameters as JSON.',
description: 'Body parameters as JSON or RAW.',
},
{
displayName: 'Body Parameters',
@ -554,13 +576,13 @@ export class HttpRequest implements INodeType {
requestOptions[optionData.name] = tempValue;
// @ts-ignore
if (typeof requestOptions[optionData.name] !== 'object') {
// If it is not an object it must be JSON so parse it
if (typeof requestOptions[optionData.name] !== 'object' && options.bodyContentType !== 'raw') {
// If it is not an object && bodyContentType is not 'raw' it must be JSON so parse it
try {
// @ts-ignore
requestOptions[optionData.name] = JSON.parse(requestOptions[optionData.name]);
} catch (e) {
throw new Error(`The data in "${optionData.displayName}" is no valid JSON.`);
throw new Error(`The data in "${optionData.displayName}" is no valid JSON. Set Body Content Type to "RAW/Custom" for XML or other types of payloads`);
}
}
}
@ -592,6 +614,14 @@ export class HttpRequest implements INodeType {
}
}
// Add Content Type if any are set
if (options.bodyContentCustomMIMEType) {
if(requestOptions.headers === undefined) {
requestOptions.headers = {};
}
requestOptions.headers['Content-Type'] = options.bodyContentCustomMIMEType;
}
// Add credentials if any are set
if (httpBasicAuth !== undefined) {
requestOptions.auth = {
@ -612,6 +642,8 @@ export class HttpRequest implements INodeType {
if (responseFormat === 'file') {
requestOptions.encoding = null;
} else if(options.bodyContentType === 'raw') {
requestOptions.json = false;
} else {
requestOptions.json = true;
}