From 85ea4e995a75abe061f6fc375ea0481084dddd43 Mon Sep 17 00:00:00 2001 From: schererleander Date: Tue, 20 Jan 2026 08:34:54 +0100 Subject: initial commit --- .../ESP_Async_WebServer/examples/Params/Params.ino | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 libraries/ESP_Async_WebServer/examples/Params/Params.ino (limited to 'libraries/ESP_Async_WebServer/examples/Params/Params.ino') diff --git a/libraries/ESP_Async_WebServer/examples/Params/Params.ino b/libraries/ESP_Async_WebServer/examples/Params/Params.ino new file mode 100644 index 0000000..2c438a5 --- /dev/null +++ b/libraries/ESP_Async_WebServer/examples/Params/Params.ino @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov + +// +// Query parameters and body parameters +// + +#include +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) +#include +#include +#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) +#include +#include +#endif + +#include + +static AsyncWebServer server(80); + +static const char *htmlContent PROGMEM = R"( + + + + POST Request with Multiple Parameters + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +)"; + +static const size_t htmlContentLength = strlen_P(htmlContent); + +void setup() { + Serial.begin(115200); + +#ifndef CONFIG_IDF_TARGET_ESP32H2 + WiFi.mode(WIFI_AP); + WiFi.softAP("esp-captive"); +#endif + + // Get query parameters + // + // curl -v http://192.168.4.1/?who=Bob + // + server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { + if (request->hasParam("who")) { + Serial.printf("Who? %s\n", request->getParam("who")->value().c_str()); + } + + request->send(200, "text/html", (uint8_t *)htmlContent, htmlContentLength); + }); + + // Get form body parameters + // + // curl -v -H "Content-Type: application/x-www-form-urlencoded" -d "who=Carl" -d "param=value" http://192.168.4.1/ + // + server.on("/", HTTP_POST, [](AsyncWebServerRequest *request) { + // display params + size_t count = request->params(); + for (size_t i = 0; i < count; i++) { + const AsyncWebParameter *p = request->getParam(i); + Serial.printf("PARAM[%u]: %s = %s\n", i, p->name().c_str(), p->value().c_str()); + } + + // get who param + String who; + if (request->hasParam("who", true)) { + who = request->getParam("who", true)->value(); + } else { + who = "No message sent"; + } + request->send(200, "text/plain", "Hello " + who + "!"); + }); + + server.begin(); +} + +// not needed +void loop() { + delay(100); +} -- cgit v1.3.1