arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
282 stars 170 forks source link

Is there an equivalent of getstream() #99

Closed thehigherlife closed 3 years ago

thehigherlife commented 3 years ago

I'm trying to work with ArduinoHttpClient and ArduinoJson.

The problem I'm having is that when I get the json document out of httpclient.getresponse() that because its a string it creates a lot of overheard for the size of the json document when I then need to copy the json document into deserializeJson(). Their documentation suggests that I use http.getStream seen here: https://arduinojson.org/v6/how-to/use-arduinojson-with-httpclient/ but there doesn't seem to be an equivalent way to do this. What's the best way to avoid this issue?

This code produces this error:

deserializeJson() failed: NoMemory


  String response = http.getresponse();
  Serial.println(statusCode);
  Serial.println(http.responseBody());
  //calculated from here: https://arduinojson.org/v6/assistant/
  // create the json object to store my data i'm getting back
  DynamicJsonDocument doc(512);
  // Deserialize the JSON document
  DeserializationError error = deserializeJson(doc, response);
  // Test if parsing succeeds.
thehigherlife commented 3 years ago

I ended up just converting the string to a char before passing it into ArduinoJson and that seemed to work.