A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add method to fetch json content for http service
Geob9a2c5405437
diff --git a/src/Services/HttpService.cpp b/src/Services/HttpService.cppindex e364e20f..4b2fc5bc 100644--- a/src/Services/HttpService.cpp+++ b/src/Services/HttpService.cpp@@ -116,6 +116,33 @@ void HttpService::getTask(void* pv)vTaskDelete(nullptr);}+std::string HttpService::fetchJson(const std::string& url ,int bodyMaxBytes)+{+ constexpr int timeout_ms = 10000;+ constexpr bool insecure = true;+ constexpr int stack_bytes = 20000;+ constexpr int core = 1;++ // Task+ startGetTask(url, timeout_ms, bodyMaxBytes,+ insecure, stack_bytes, core, true);++ // Wait for response+ unsigned long start = millis();+ while (!isResponseReady() && millis() - start < timeout_ms) {+ delay(100);+ }++ if (!isResponseReady()) {+ return "ERROR: timeout waiting response";+ }++ // Get response+ std::string resp = lastResponse();++ return resp;+}+std::string HttpService::getJsonBody(HTTPClient& http, int bodyMaxBytes){std::string out;diff --git a/src/Services/HttpService.h b/src/Services/HttpService.hindex 9cd732e8..dd485204 100644--- a/src/Services/HttpService.h+++ b/src/Services/HttpService.h@@ -15,6 +15,9 @@ public:void startGetTask(const std::string& url, int timeout_ms, int bodyMaxBytes, bool insecure,int stack_bytes = 20000, int core = 1, bool onlyContent = false);+ // Fetch JSON data from a URL+ std::string fetchJson(const std::string& url, int bodyMaxBytes);+// Verify if the response is readybool isResponseReady() const noexcept;