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 bodyValue = null;
|
||||
|
||||
if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") {
|
||||
bodyValue = JSON.parse(this.body);
|
||||
contentType = "application/json";
|
||||
} else if (this.body && (this.httpBodyEncoding === "xml")) {
|
||||
bodyValue = this.body;
|
||||
contentType = "text/xml; charset=utf-8";
|
||||
if (this.body && (typeof this.body === "string" && this.body.trim().length > 0)) {
|
||||
if (!this.httpBodyEncoding || this.httpBodyEncoding === "json") {
|
||||
try {
|
||||
bodyValue = JSON.parse(this.body);
|
||||
contentType = "application/json";
|
||||
} 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
|
||||
const options = {
|
||||
url: this.url,
|
||||
method: (this.method || "get").toLowerCase(),
|
||||
...(bodyValue ? { data: bodyValue } : {}),
|
||||
timeout: this.interval * 1000 * 0.8,
|
||||
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",
|
||||
|
@ -303,6 +308,10 @@ class Monitor extends BeanModel {
|
|||
},
|
||||
};
|
||||
|
||||
if (bodyValue) {
|
||||
options.data = bodyValue;
|
||||
}
|
||||
|
||||
if (this.proxy_id) {
|
||||
const proxy = await R.load("proxy", this.proxy_id);
|
||||
|
||||
|
|
Loading…
Reference in New Issue