Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant