Skip to content

ESP32 HTTP POST with JSON Body Fails

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 HTTP POST with JSON Body Fails. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 sends POST with JSON body but server returns 400 Bad Request or ignores data.

Quick Fix

Wrong

HTTPClient http;
http.begin("http://api.example.com/data");
http.POST("{\'temp\':22.5}");
Server returns 400 Bad Request or 415 Unsupported Media Type.
HTTPClient http;
http.begin("http://api.example.com/data");
http.addHeader("Content-Type", "application/json");
String json = "{\'temp\':22.5,\'humidity\':60}";
int code = http.POST(json);
if (code == 200 || code == 201) {
  Serial.printf("POST success: %s", http.getString().c_str());
}
http.end();
POST success: {"id": 123, "status": "created"}

Prevention

Set Content-Type: application/json header before POST. Escape double quotes properly. Check 200/201 for success. Use ArduinoJson library. Validate JSON before sending.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### How do I construct JSON on ESP32?

Use ArduinoJson: JsonDocument doc; doc["temp"] = 22.5; serializeJson(doc, jsonString); Handles escaping properly.

What is the max JSON payload size?

ESP32 heap limits JSON to ~40 KB with ArduinoJson static allocation. Use DynamicJsonDocument for larger.

Why does my POST get truncated?

Default HTTPClient buffer may be too small. Call http.setTimeout() to allow larger payloads.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro