mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge branch 'pr_2078' into dev
This commit is contained in:
commit
fe0d0f08e4
@ -203,28 +203,32 @@ module.exports = function(RED) {
|
|||||||
var payload = null;
|
var payload = null;
|
||||||
|
|
||||||
if (method !== 'GET' && method !== 'HEAD' && typeof msg.payload !== "undefined") {
|
if (method !== 'GET' && method !== 'HEAD' && typeof msg.payload !== "undefined") {
|
||||||
if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
|
if (opts.headers['content-type'] == 'multipart/form-data' && typeof payload === "object") {
|
||||||
payload = msg.payload;
|
opts.formData = msg.payload;
|
||||||
} else if (typeof msg.payload == "number") {
|
|
||||||
payload = msg.payload+"";
|
|
||||||
} else {
|
} else {
|
||||||
if (opts.headers['content-type'] == 'application/x-www-form-urlencoded') {
|
if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {
|
||||||
payload = querystring.stringify(msg.payload);
|
payload = msg.payload;
|
||||||
|
} else if (typeof msg.payload == "number") {
|
||||||
|
payload = msg.payload+"";
|
||||||
} else {
|
} else {
|
||||||
payload = JSON.stringify(msg.payload);
|
if (opts.headers['content-type'] == 'application/x-www-form-urlencoded') {
|
||||||
if (opts.headers['content-type'] == null) {
|
payload = querystring.stringify(msg.payload);
|
||||||
opts.headers[ctSet] = "application/json";
|
} else {
|
||||||
|
payload = JSON.stringify(msg.payload);
|
||||||
|
if (opts.headers['content-type'] == null) {
|
||||||
|
opts.headers[ctSet] = "application/json";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (opts.headers['content-length'] == null) {
|
||||||
if (opts.headers['content-length'] == null) {
|
if (Buffer.isBuffer(payload)) {
|
||||||
if (Buffer.isBuffer(payload)) {
|
opts.headers[clSet] = payload.length;
|
||||||
opts.headers[clSet] = payload.length;
|
} else {
|
||||||
} else {
|
opts.headers[clSet] = Buffer.byteLength(payload);
|
||||||
opts.headers[clSet] = Buffer.byteLength(payload);
|
}
|
||||||
}
|
}
|
||||||
|
opts.body = payload;
|
||||||
}
|
}
|
||||||
opts.body = payload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method == 'GET' && typeof msg.payload !== "undefined" && paytoqs) {
|
if (method == 'GET' && typeof msg.payload !== "undefined" && paytoqs) {
|
||||||
|
@ -78,5 +78,18 @@
|
|||||||
<p>If <code>msg.payload</code> is an Object, the node will automatically set the content type
|
<p>If <code>msg.payload</code> is an Object, the node will automatically set the content type
|
||||||
of the request to <code>application/json</code> and encode the body as such.</p>
|
of the request to <code>application/json</code> and encode the body as such.</p>
|
||||||
<p>To encode the request as form data, <code>msg.headers["content-type"]</code> should be set to <code>application/x-www-form-urlencoded</code>.</p>
|
<p>To encode the request as form data, <code>msg.headers["content-type"]</code> should be set to <code>application/x-www-form-urlencoded</code>.</p>
|
||||||
|
<h4>File Upload</h4>
|
||||||
|
<p>To perform a file upload, <code>msg.headers["content-type"]</code> should be set to <code>multipart/form-data</code>
|
||||||
|
and the <code>msg.payload</code> passed to the node must be an object with the following structure:</p>
|
||||||
|
<pre>{
|
||||||
|
"KEY": {
|
||||||
|
"value": FILE_CONTENTS,
|
||||||
|
"options": {
|
||||||
|
"filename": "FILENAME"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}</code></pre>
|
||||||
|
<p>The values of <code>KEY</code>, <code>FILE_CONTENTS</code> and <code>FILENAME</code>
|
||||||
|
should be set to the appropriate values.</p>
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user