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

AsyncWebServerResponse send back to client through route/path #1449

Open
noellemar opened this issue Nov 13, 2024 · 0 comments
Open

AsyncWebServerResponse send back to client through route/path #1449

noellemar opened this issue Nov 13, 2024 · 0 comments

Comments

@noellemar
Copy link

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);

});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant