mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-18 04:04:41 -05:00
Fix json body after xml body added
This commit is contained in:
parent
487eae71c7
commit
a7b49fcd98
@ -276,19 +276,24 @@ class Monitor extends BeanModel {
|
|||||||
let contentType = null;
|
let contentType = null;
|
||||||
let bodyValue = null;
|
let bodyValue = null;
|
||||||
|
|
||||||
if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") {
|
if (this.body && (typeof this.body === "string" && this.body.trim().length > 0)) {
|
||||||
bodyValue = JSON.parse(this.body);
|
if (!this.httpBodyEncoding || this.httpBodyEncoding === "json") {
|
||||||
contentType = "application/json";
|
try {
|
||||||
} else if (this.body && (this.httpBodyEncoding === "xml")) {
|
bodyValue = JSON.parse(this.body);
|
||||||
bodyValue = this.body;
|
contentType = "application/json";
|
||||||
contentType = "text/xml; charset=utf-8";
|
} catch (e) {
|
||||||
|
throw new Error("Your JSON body is invalid. " + e.message);
|
||||||
|
}
|
||||||
|
} else if (this.httpBodyEncoding === "xml") {
|
||||||
|
bodyValue = this.body;
|
||||||
|
contentType = "text/xml; charset=utf-8";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axios Options
|
// Axios Options
|
||||||
const options = {
|
const options = {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: (this.method || "get").toLowerCase(),
|
method: (this.method || "get").toLowerCase(),
|
||||||
...(bodyValue ? { data: bodyValue } : {}),
|
|
||||||
timeout: this.interval * 1000 * 0.8,
|
timeout: this.interval * 1000 * 0.8,
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||||
@ -303,6 +308,10 @@ class Monitor extends BeanModel {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (bodyValue) {
|
||||||
|
options.data = bodyValue;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.proxy_id) {
|
if (this.proxy_id) {
|
||||||
const proxy = await R.load("proxy", this.proxy_id);
|
const proxy = await R.load("proxy", this.proxy_id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user