|
27 | 27 |
|
28 | 28 | static AsyncWebServer server(80); |
29 | 29 |
|
| 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 | + |
30 | 43 | // user defined functions that turns out to have similar signatures to the ones in global header |
31 | 44 | int stringToMethod(const String &) { |
32 | 45 | return 0; |
@@ -71,6 +84,13 @@ void setup() { |
71 | 84 | request->send(200, "text/plain", "Hello"); |
72 | 85 | }); |
73 | 86 |
|
| 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 | + |
74 | 94 | // curl -v -X HEAD http://192.168.4.1/custom => answers |
75 | 95 | // curl -v -X OPTIONS http://192.168.4.1/custom => answers |
76 | 96 | // curl -v -X POST http://192.168.4.1/custom => no answer |
|
0 commit comments