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+ #if ASYNC_JSON_SUPPORT == 1
33+ // https://github.com/ESP32Async/ESPAsyncWebServer/issues/404
34+ static void handlePostTest (AsyncWebServerRequest *req, JsonVariant &json) {
35+ AsyncWebServerResponse *response;
36+ if (req->method () == WebRequestMethod::HTTP_POST) {
37+ response = req->beginResponse (200 , " application/json" , " {\" msg\" : \" OK\" }" );
38+ } else {
39+ response = req->beginResponse (501 , " application/json" , " {\" msg\" : \" Not Implemented\" }" );
40+ }
41+ req->send (response);
42+ }
43+ #endif
44+
3245void setup () {
3346 Serial.begin (115200 );
3447
@@ -48,6 +61,13 @@ void setup() {
4861 request->send (200 , " text/plain" , " Hello" );
4962 });
5063
64+ #if ASYNC_JSON_SUPPORT == 1
65+ // curl -v http://192.168.4.1/test => Not Implemented
66+ // curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
67+ AsyncCallbackJsonWebHandler *testHandler = new AsyncCallbackJsonWebHandler (" /test" , handlePostTest);
68+ server.addHandler (testHandler);
69+ #endif
70+
5171 server.begin ();
5272}
5373
You can’t perform that action at this time.
0 commit comments