Adding x-www-form-urlencoded (#3499)

* Adding x-www-form-urlencoded

* Adding example of x-www-form-urlencoding to body.

* A bit cleaner.

* Update server/model/monitor.js

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update src/pages/EditMonitor.vue

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update src/pages/EditMonitor.vue

Co-authored-by: Matthew Nickson <mnickson@sidingsmedia.com>

* Add simple test

---------

Co-authored-by: Anders Kvist <ak@cego.dk>
Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
Co-authored-by: Matthew Nickson <mnickson@sidingsmedia.com>
This commit is contained in:
Anders Kvist 2023-09-09 12:05:25 +02:00 committed by GitHub
parent 9f7f7a182e
commit f0c54be43f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -431,6 +431,9 @@ class Monitor extends BeanModel {
} catch (e) { } catch (e) {
throw new Error("Your JSON body is invalid. " + e.message); throw new Error("Your JSON body is invalid. " + e.message);
} }
} else if (this.httpBodyEncoding === "form") {
bodyValue = this.body;
contentType = "application/x-www-form-urlencoded";
} else if (this.httpBodyEncoding === "xml") { } else if (this.httpBodyEncoding === "xml") {
bodyValue = this.body; bodyValue = this.body;
contentType = "text/xml; charset=utf-8"; contentType = "text/xml; charset=utf-8";

View File

@ -251,6 +251,12 @@ let needSetup = false;
log.debug("test", request.body); log.debug("test", request.body);
response.send("OK"); response.send("OK");
}); });
app.post("/test-x-www-form-urlencoded", async (request, response) => {
log.debug("test", request.headers);
log.debug("test", request.body);
response.send("OK");
});
} }
// Robots.txt // Robots.txt

View File

@ -654,6 +654,7 @@
<label for="httpBodyEncoding" class="form-label">{{ $t("Body Encoding") }}</label> <label for="httpBodyEncoding" class="form-label">{{ $t("Body Encoding") }}</label>
<select id="httpBodyEncoding" v-model="monitor.httpBodyEncoding" class="form-select"> <select id="httpBodyEncoding" v-model="monitor.httpBodyEncoding" class="form-select">
<option value="json">JSON</option> <option value="json">JSON</option>
<option value="form">x-www-form-urlencoded</option>
<option value="xml">XML</option> <option value="xml">XML</option>
</select> </select>
</div> </div>
@ -1002,6 +1003,9 @@ message HealthCheckResponse {
</soap:Body> </soap:Body>
</soap:Envelope>` ]); </soap:Envelope>` ]);
} }
if (this.monitor && this.monitor.httpBodyEncoding === "form") {
return this.$t("Example:", [ "key1=value1&key2=value2" ]);
}
return this.$t("Example:", [ ` return this.$t("Example:", [ `
{ {
"key": "value" "key": "value"