Hi all,
We are testing our library with http request on ESP32 WROOM 32. Here is onqe question that I can't figure out.
In the library, we'd like to process a http response sent from the server in the set up() section. The idea is like this.
setup(){
TokenCreate("hello.com", "hello.com",1440);
}
TokenCreate(char* URL, char* Subname, char* Suber, int expiretime){
Serial.print("The subscription is associated with the Subscripter: ");
Serial.println(Suber);
StaticJsonDocument<200> root;
root["subscriber"] = Suber;
root["subscription"] = Subname;
root["expiresInMinutes"] = expiretime;
String body2send = "";
serializeJsonPretty(root, body2send);
if (_networkClient->connect(URL, 443)) {
Serial.println("Connected to the server to request token!");
// Make a HTTP request:
_networkClient->println("POST /notification2/token HTTP/1.1");
_networkClient->print("Host: ");
_networkClient->println(URL);
_networkClient->print("Authorization: Basic ");
_networkClient->println(_base64);
_networkClient->println("Content-Type: application/json");
_networkClient->print("Content-Length: ");
_networkClient->println(body2send.length());
_networkClient->println("Accept: application/json");
_networkClient->println();
_networkClient->println(body2send);
}
//Here is quite import for library and it doesn't work!!
String msg = "";
while (_networkClient->available()) {
char c = _networkClient->read();
msg += c;
}
Serial.println(msg);
}
The request has been successfully sent out. But the section "while" has been skipped somehow and it never get itself executed and we don't know why.
String msg = "";
while (_networkClient->available()) {
char c = _networkClient->read();
msg += c;
}
Serial.println(msg);
As you can see, we are waiting the msg sent back from server(it does send message!!) but it prints blanket as if it doesn't exist.
BTW: _networkClient is &Client
Help us please!