Skip to content

Commit e7d0c39

Browse files
committed
Close witnessmenow#11: sendGetToTelegram() parses HTTP/1.0 answers properly
1 parent 0c64f34 commit e7d0c39

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ String UniversalTelegramBot::buildCommand(const String& cmd) {
6666
}
6767

6868
String UniversalTelegramBot::sendGetToTelegram(const String& command) {
69-
String mess;
70-
long now;
69+
String body, headers;
7170
bool avail;
7271

7372
// Connect with api.telegram.org if not already connected
@@ -91,30 +90,14 @@ String UniversalTelegramBot::sendGetToTelegram(const String& command) {
9190
char c;
9291
int ch_count = 0;
9392
client->print(F("GET /"));
94-
client->println(command);
95-
now = millis();
96-
avail = false;
97-
while (millis() - now < longPoll * 1000 + waitForResponse) {
98-
while (client->available()) {
99-
char c = client->read();
100-
if (ch_count < maxMessageLength) {
101-
mess += c;
102-
ch_count++;
103-
}
104-
avail = true;
105-
}
106-
if (avail) {
107-
#ifdef _debug
108-
Serial.println();
109-
Serial.println(mess);
110-
Serial.println();
111-
#endif
112-
break;
113-
}
114-
}
93+
client->print(command);
94+
client->println(F(" HTTP/1.0"));
95+
client->println(F("Host: " HOST));
96+
client->println(F(""));
97+
readHTTPAnswer(body, headers);
11598
}
11699

117-
return mess;
100+
return body;
118101
}
119102

120103
bool UniversalTelegramBot::readHTTPAnswer(String &body, String &headers) {

0 commit comments

Comments
 (0)