From 3a508a3ec47a8e835a37789dc6a4e87135df3101 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 20 Nov 2025 14:58:54 +0100 Subject: [PATCH] fixes #2752 --- src/web/WebAPIService.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index 85f6bfbd9..f6f45dc3a 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -152,11 +152,15 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) { // 401 (unauthorized) // 400 (invalid) int ret_codes[7] = {400, 200, 404, 400, 401, 400, 404}; - response->setCode(ret_codes[return_code]); - response->setLength(); - response->setContentType("application/json; charset=utf-8"); - request->send(response); + + // serialize JSON to string to ensure correct content-length and avoid HTTP parsing errors (issue #2752) + std::string output_str; + serializeJson(output, output_str); + + request->send(ret_codes[return_code], "application/json; charset=utf-8", output_str.c_str()); + api_count_++; + delete response; #if defined(EMSESP_UNITY) // store the result so we can test with Unity later