forked from amcewen/HttpClient
-
Notifications
You must be signed in to change notification settings - Fork 172
Open
Labels
type: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
My code looks roughly like:
char json_string[512];
int length = mylib.sprint_json(json_string);
Serial.println("Sending JSON:");
Serial.println(json_string);
Serial.print("Length: ");
Serial.println(length);
client.beginRequest();
client.post("/");
client.sendHeader("Host", "my.hostname.tld");
client.sendHeader("Content-Type", "application/json");
client.sendHeader("Content-Length", length);
client.beginBody();
client.print(json_string);
client.endRequest();
int statusCode = client.responseStatusCode();
String response = client.responseBody();
mylib.sprint_json
is essentially an sprintf()
wrapper.
This doesn't work. The request never goes out.
If I change the post request to:
client.post("/", "application/json", json_string);
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...
Metadata
Metadata
Assignees
Labels
type: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Activity
jonasbarsten commentedon Sep 6, 2024
Did some testing and it seems complex POST requests only work with json strings shorter than 504 characters.
jonasbarsten commentedon Sep 6, 2024
I solved it like this for now: