add missing "\r\n" to GET header

This commit is contained in:
proddy
2026-05-29 16:15:54 +01:00
parent c7816a644f
commit 7b6d60691c

View File

@@ -748,15 +748,19 @@ int http_request(std::string url, const std::string & method, const std::string
ssl_client->print(value.c_str()); ssl_client->print(value.c_str());
} else { } else {
ssl_client->println("Connection: close"); ssl_client->println("Connection: close");
ssl_client->print("\r\n"); // terminate headers - without this the server never responds
} }
auto ms = millis(); auto ms = millis();
while (ssl_client->connected() && !ssl_client->available() && millis() - ms < 3000) { while (ssl_client->connected() && !ssl_client->available() && millis() - ms < 3000) {
delay(0); delay(1);
} }
while (ssl_client->available()) { while (ssl_client->available()) {
result += (char)ssl_client->read(); result += (char)ssl_client->read();
} }
ssl_client->stop(); ssl_client->stop();
index = result.find_first_of(' '); index = result.find_first_of(' ');
if (index != std::string::npos) { if (index != std::string::npos) {
httpResult = stoi(result.substr(index + 1, 3)); httpResult = stoi(result.substr(index + 1, 3));
@@ -817,6 +821,7 @@ std::string compute(const std::string & expr) {
std::string value = doc[value_s] | ""; std::string value = doc[value_s] | "";
std::string method = doc[method_s] | "GET"; std::string method = doc[method_s] | "GET";
std::string result; std::string result;
int httpResult = http_request(url, method, value, doc[header_s].as<JsonObjectConst>(), result); int httpResult = http_request(url, method, value, doc[header_s].as<JsonObjectConst>(), result);
if (httpResult == 200) { if (httpResult == 200) {
std::string key = doc[key_s] | ""; std::string key = doc[key_s] | "";
@@ -847,6 +852,7 @@ std::string compute(const std::string & expr) {
} }
expr_new.replace(f, e - f, result); expr_new.replace(f, e - f, result);
} else if (httpResult != 0) { } else if (httpResult != 0) {
// httpResult of 0 means no url
EMSESP::logger().warning("URL command failed with https code: %d, response: %s", httpResult, result.c_str()); EMSESP::logger().warning("URL command failed with https code: %d, response: %s", httpResult, result.c_str());
} }
} }