Open kaysond opened 2 months ago
Did some testing and it seems complex POST requests only work with json strings shorter than 504 characters.
I solved it like this for now:
String input = "suuuuuuuper-loooooooooooooooong-striiiiiiiiiiiing";
const size_t contentLength = input.length();
client.beginRequest();
client.post(path);
client.sendHeader("Content-Type", "application/json");
client.sendHeader("Content-Length", contentLength);
client.beginBody();
constexpr size_t chunkSize = 64;
for (size_t i = 0; i < contentLength; i = i + chunkSize) {
if (contentLength - i < chunkSize) {
String chunk = input.substring(i);
client.print(chunk);
} else {
String chunk = input.substring(i, chunkSize + i);
client.print(chunk);
}
}
client.endRequest();
My code looks roughly like:
mylib.sprint_json
is essentially ansprintf()
wrapper.This doesn't work. The request never goes out.
If I change the post request to:
it works just fine.
Am I doing something wrong? I copied the example. From the
Serial.println()
s, I can see that the string and length are correct...