File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929
3030static AsyncWebServer server (80 );
3131
32+ // https://github.com/ESP32Async/ESPAsyncWebServer/issues/404
33+ static void handlePostTest (AsyncWebServerRequest *req, JsonVariant &json) {
34+ AsyncWebServerResponse *response;
35+ Serial.printf (" HTTP method: %u\n " , req->method ());
36+ Serial.printf (" WebRequestMethod::HTTP_POST: %u\n " , WebRequestMethod::HTTP_POST);
37+ if (req->method () == WebRequestMethod::HTTP_POST) {
38+ response = req->beginResponse (200 , " application/json" , " {\" msg\" : \" OK\" }" );
39+ } else {
40+ response = req->beginResponse (501 , " application/json" , " {\" msg\" : \" Not Implemented\" }" );
41+ }
42+ req->send (response);
43+ }
44+
3245void setup () {
3346 Serial.begin (115200 );
3447
@@ -48,6 +61,11 @@ void setup() {
4861 request->send (200 , " text/plain" , " Hello" );
4962 });
5063
64+ // curl -v http://192.168.4.1/test => Not Implemented
65+ // curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
66+ AsyncCallbackJsonWebHandler *testHandler = new AsyncCallbackJsonWebHandler (" /test" , handlePostTest);
67+ server.addHandler (testHandler);
68+
5169 server.begin ();
5270}
5371
You can’t perform that action at this time.
0 commit comments