Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

AsyncWebServerResponse send back to client through route/path #1449

@noellemar

Description

@noellemar

Hello,

i have established Async Server listening to port, and received JSON data, parse them and then needs to return a response to client by adding headers and route/path to which will yield a successful acknowledgement.

but unfortunately i found arguments in have only (HTTPCODE, "Content-Type", Message), then how can i add client path (example, POST /clientROUTE HTTP/1.1)?

here is my main part of code, needs help.

serverWeb.on(
"/",
HTTP_POST,
[](AsyncWebServerRequest * request){},
NULL,
[](AsyncWebServerRequest * request, uint8_t *data, size_t len, size_t index, size_t total) {
for (size_t i = 0; i < len; i++) {
Serial.write(data[i]);
}

  Serial.println();
  // Serial.print("Data:");
  // Serial.println((const char*)data); 

  String c = (const char*)data;

  if(ptsFunction(c)){
Serial.println("\nSUCCESS");

//send back to client

char* requestClient = (char ) ps_malloc(101024 * sizeof(char));
sprintf(requestClient,"{"A":"AA","B":%d}",i);
Serial.println(F("send back to Client response"));
AsyncWebServerResponse *response = request->beginResponse(200, "Content-Type: application/json", String(requestClient).c_str());
response->addHeader("header1", "Value1");
response->addHeader("header2", "Value2");
response->addHeader("header3", "Value3");
request->send(response);

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions