Skip to content

Since 3.10.1 Any AsyncCallbackJsonWebHandler Post Handler is returning 404 #404

@alanaquilina

Description

@alanaquilina

Platform

ESP32

IDE / Tooling

Arduino (IDE/CLI)

What happened?

I updated from 3.9.6 to 3.10.1 and this code is now always returning 404

AsyncCallbackJsonWebHandler* loginHandler = new AsyncCallbackJsonWebHandler("/oca-timer/login", handlePostLogin);        
server.addHandler(loginHandler);

The first line in the handler is just a Serial Print but it never shows.

I downgraded to 3.10.0 and it worked.

AsyncTCP is 3.4.10

Stack Trace

n/a

P.S. On another note the please decode it link does not work

Minimal Reproductible Example (MRE)

#include <Arduino.h>
#include <AsyncTCP.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>

AsyncWebServer server(80);
void connectToWifi (char* ssid, char*password)
{
  WiFi.disconnect(false);
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);  

  bool ret = false;
  Serial.println("");
  int i = 0;
  while (WiFi.status() != WL_CONNECTED && i < 60) {
    delay(1000);
    Serial.print(".");
    i++;
  }
  Serial.println("");
  char msg[100];
  sprintf (msg, "WiFi connected IP: %d.%d.%d.%d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
  Serial.println (msg);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);    
  connectToWifi("SSID", "PASSWORD");

  AsyncCallbackJsonWebHandler *testHandler =
      new AsyncCallbackJsonWebHandler("/test", handlePostTest);
  server.addHandler(testHandler);
  server.begin();
  
}

void handlePostTest (AsyncWebServerRequest *req, JsonVariant &json)
{  
  Serial.println ("In Test Handler");
  AsyncWebServerResponse *response;
  if (req->method() == HTTP_POST) {
     response = req->beginResponse(200, "application/json", "{\"msg\": \"OK\"}");      
  }
  else
  {
    req->beginResponse(501, "application/json", "{\"msg\": \"Not Implemented\"}");
  }
  req->send(response);  
}

void loop() {
  // put your main code here, to run repeatedly:

}

v 3.10.0
Image

v3.10.1

Image

I confirm that:

  • I have read the documentation.
  • I have searched for similar discussions.
  • I have searched for similar issues.
  • I have looked at the examples.
  • I have upgraded to the lasted version of ESPAsyncWebServer (and AsyncTCP for ESP32).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions