http.getString
Posted: Fri Apr 06, 2018 5:24 pm
I am using the ESP-WROOM-32 module programming with Arduino in windows.
I want to get the Token ID of Firebase to connect, I do the POST, the server responds to me ok, but when I want to read the answer the program hangs and stops executing more code.
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* ssid = "...";
const char* password = "...";
void setup()
{
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println("************* Firebase_token3 *****************");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
HTTPClient http;
Serial.println("[HTTP] Iniciando...\n");
http.begin("https://www.googleapis.com/identitytool ... sword?key=......");
http.addHeader("HOST","www.googleapis.com");
http.addHeader("Content-Length","82");
http.addHeader("Content-Type","application/json");
int httpCode = http.POST("{\"email\":\"...@....\",\"password\":\"......\",\"returnSecureToken\":true}");
if ( httpCode > 0 )
{
Serial.print("Codigo: ");
Serial.println(httpCode); // Up here all right, I can see 200 in the console
String respuesta = http.getString();
Serial.println(respuesta); // This line of code is never executed
Serial.println("Exito?");
}
else
{
Serial.println("Error comunicacion HTTP.... ");
}
http.end();
delay(5000);
}
I want to get the Token ID of Firebase to connect, I do the POST, the server responds to me ok, but when I want to read the answer the program hangs and stops executing more code.
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* ssid = "...";
const char* password = "...";
void setup()
{
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println("************* Firebase_token3 *****************");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
HTTPClient http;
Serial.println("[HTTP] Iniciando...\n");
http.begin("https://www.googleapis.com/identitytool ... sword?key=......");
http.addHeader("HOST","www.googleapis.com");
http.addHeader("Content-Length","82");
http.addHeader("Content-Type","application/json");
int httpCode = http.POST("{\"email\":\"...@....\",\"password\":\"......\",\"returnSecureToken\":true}");
if ( httpCode > 0 )
{
Serial.print("Codigo: ");
Serial.println(httpCode); // Up here all right, I can see 200 in the console
String respuesta = http.getString();
Serial.println(respuesta); // This line of code is never executed
Serial.println("Exito?");
}
else
{
Serial.println("Error comunicacion HTTP.... ");
}
http.end();
delay(5000);
}