MCPcopy Create free account
hub / github.com/PricelessToolkit/MailBoxGuard / sendGetHA

Method sendGetHA

Code/Arduino_libraries/HARestAPI/src/HARestAPI.cpp:87–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87String HARestAPI::sendGetHA(String URL)
88{
89 String posturl, replystr;
90 this->http = new HTTPClient();
91
92 if (_ssl)
93 {
94 posturl = "https://" + _serverip + ":" + _port + URL;
95 if (_debug)
96 {
97 Serial.print("Connecting: ");
98 Serial.println(posturl);
99 }
100 if ( _fingerprint.length() > 0)
101 {
102 #ifdef ESP8266
103 wsclient->setFingerprint(_fingerprint.c_str());
104 #elseif defined(ESP32)
105 if (wsclient->verify(_fingerprint.c_str(), _serverip.c_str()))
106 {
107 Serial.println("certificate matches");
108 }
109 else
110 {
111 Serial.println("certificate doesn't match");
112 _skip_sendurl = true;
113 }
114 #endif
115 }
116 else
117 {
118 wsclient->setInsecure();
119 }
120 if (!_skip_sendurl)
121 {
122 http->begin(*wsclient, posturl);
123 if (_time_out)
124 http->setTimeout(_time_out);
125 http->addHeader("User-Agent", "HA Rest API Client");
126 http->addHeader("Accept", "*/*");
127 http->addHeader("Authorization", "Bearer " + _password);
128 int httpCode = http->GET();
129 if (httpCode > 0)
130 {
131 if (_debug)
132 Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
133 if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY)
134 {
135 replystr += http->getString();
136 }
137 }
138 else
139 {
140 if (_debug)
141 Serial.printf("[HTTPS] GET... failed, error: %s\n", http->errorToString(httpCode).c_str());
142 }
143 http->end();
144 }

Callers

nothing calls this directly

Calls 6

getStringMethod · 0.80
printMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected