You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you let me know why the following code is losing the string value when it's used outside of if-statement. Out side of if-statement the "original" variable **payload ** is getting back the initial value x
See the code and the output
String httpsGETRequest(const char* serverName) {
String payload = "x";
String payload1 = "y";
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setFingerprint(fingerprint);
// Or, if you happy to ignore the SSL certificate, then use the following line instead:
client->setInsecure();
HTTPClient https;
Serial.print("[HTTPS] begin...\n");
if (https.begin(*client, serverName)) { // HTTPS
Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
Serial.println("getting payload");
String payload = https.getString();
payload1=payload;
Serial.print ("PRINT payload (inside-if): ");
Serial.println(payload);
payload1=payload;
Serial.print ("PRINT payload1 (inside-if): ");
Serial.println(payload1);**
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
Serial.print ("PRINT payload (outside-if): ");
Serial.println(payload);
Serial.print ("PRINT payload1 (outside-if): ");
Serial.print("print payload1");
Serial.println(payload1);
https.end();
return payload;
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Could you let me know why the following code is losing the string value when it's used outside of if-statement. Out side of if-statement the "original" variable **payload ** is getting back the initial value x
See the code and the output
String httpsGETRequest(const char* serverName) {
}
[HTTPS] begin...
[HTTPS] GET...
[HTTPS] GET... code: 200
getting payload
PRINT payload (inside-if): {"0":{"time":"2022-12-19 13:00:00","value":"27.36"},"1"-----clip-----
PRINT payload1 (inside-if): {"0":{"time":"2022-12-19 13:00:00","value":"27.36"},"1"-----clip-----
PRINT payload (outside-if): x
PRINT payload1 (outside-if): print payload1{"0":{"time":"2022-12-19 13:00:00","value":"27.36"},"1"{-----clip---
Beta Was this translation helpful? Give feedback.
All reactions