From dce3713f12ff88fa88418dee07cc36d92ae1b0cc Mon Sep 17 00:00:00 2001 From: Martin <25747549+martgras@users.noreply.github.com> Date: Mon, 3 Jan 2022 19:40:05 +0100 Subject: [PATCH] Fix HTTPRequestComponent::get_string return value (#2987) Co-authored-by: Oxan van Leeuwen --- esphome/components/http_request/http_request.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/http_request/http_request.cpp b/esphome/components/http_request/http_request.cpp index 309977a915..a80d095835 100644 --- a/esphome/components/http_request/http_request.cpp +++ b/esphome/components/http_request/http_request.cpp @@ -115,8 +115,11 @@ void HttpRequestComponent::close() { } const char *HttpRequestComponent::get_string() { - static const String STR = this->client_.getString(); - return STR.c_str(); + // The static variable is here because HTTPClient::getString() returns a String on ESP32, and we need something to + // to keep a buffer alive. + static std::string str; + str = this->client_.getString().c_str(); + return str.c_str(); } } // namespace http_request