9 namespace http_request {
11 static const char *
const TAG =
"http_request";
14 ESP_LOGCONFIG(TAG,
"HTTP Request:");
15 ESP_LOGCONFIG(TAG,
" Timeout: %ums", this->
timeout_);
16 ESP_LOGCONFIG(TAG,
" User-Agent: %s", this->
useragent_);
22 this->
url_ = std::move(url);
23 this->
secure_ = this->
url_.compare(0, 6,
"https:") == 0;
37 ESP_LOGW(TAG,
"HTTP Request failed; Not connected to network");
41 bool begin_status =
false;
42 const String url = this->
url_.c_str();
43 #if defined(USE_ESP32) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0)) 44 #if defined(USE_ESP32) || USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 7, 0) 46 this->
client_.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
48 this->
client_.setFollowRedirects(HTTPC_DISABLE_FOLLOW_REDIRECTS);
55 #if defined(USE_ESP32) 56 begin_status = this->
client_.begin(url);
57 #elif defined(USE_ESP8266) 64 ESP_LOGW(TAG,
"HTTP Request failed at the begin phase. Please check the configuration");
72 for (
const auto &header : this->
headers_) {
73 this->
client_.addHeader(header.name, header.value,
false,
true);
77 for (
auto *trigger : response_triggers)
78 trigger->process(http_code);
81 ESP_LOGW(TAG,
"HTTP Request failed; URL: %s; Error: %s", this->
url_.c_str(),
82 HTTPClient::errorToString(http_code).c_str());
87 if (http_code < 200 || http_code >= 300) {
88 ESP_LOGW(TAG,
"HTTP Request failed; URL: %s; Code: %d", this->
url_.c_str(), http_code);
94 ESP_LOGD(TAG,
"HTTP Request completed; URL: %s; Code: %d", this->
url_.c_str(), http_code);
99 #ifdef USE_HTTP_REQUEST_ESP8266_HTTPS 132 str = this->
client_.getString();
139 #endif // USE_ARDUINO
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
std::shared_ptr< BearSSL::WiFiClientSecure > wifi_client_secure_
void status_clear_warning()
void send(const std::vector< HttpRequestResponseTrigger *> &response_triggers)
void set_url(std::string url)
void status_set_warning()
std::shared_ptr< WiFiClient > get_wifi_client_()
const char * get_string()
void dump_config() override
std::list< Header > headers_
std::shared_ptr< WiFiClient > wifi_client_