File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727
2828static AsyncWebServer server (80 );
2929
30+ #if ASYNC_JSON_SUPPORT == 1
31+ // https://github.com/ESP32Async/ESPAsyncWebServer/issues/404
32+ static void handlePostTest (AsyncWebServerRequest *req, JsonVariant &json) {
33+ AsyncWebServerResponse *response;
34+ if (req->method () == WebRequestMethod::HTTP_POST) {
35+ response = req->beginResponse (200 , " application/json" , " {\" msg\" : \" OK\" }" );
36+ } else {
37+ response = req->beginResponse (501 , " application/json" , " {\" msg\" : \" Not Implemented\" }" );
38+ }
39+ req->send (response);
40+ }
41+ #endif
42+
3043// user defined functions that turns out to have similar signatures to the ones in global header
3144int stringToMethod (const String &) {
3245 return 0 ;
@@ -71,6 +84,13 @@ void setup() {
7184 request->send (200 , " text/plain" , " Hello" );
7285 });
7386
87+ #if ASYNC_JSON_SUPPORT == 1
88+ // curl -v http://192.168.4.1/test => Not Implemented
89+ // curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
90+ AsyncCallbackJsonWebHandler *testHandler = new AsyncCallbackJsonWebHandler (" /test" , handlePostTest);
91+ server.addHandler (testHandler);
92+ #endif
93+
7494 // curl -v -X HEAD http://192.168.4.1/custom => answers
7595 // curl -v -X OPTIONS http://192.168.4.1/custom => answers
7696 // curl -v -X POST http://192.168.4.1/custom => no answer
You can’t perform that action at this time.
0 commit comments