An Azure service that provides a hybrid, multi-cloud management platform for APIs.
APIM’s interactive “Try it” console in the developer portal sends requests to your APIs the same way as any other client. Intermittent empty request bodies are typically caused by how the backend framework detects whether a body is present, combined with how the request is formed.
In ASP.NET Core 7 and later, MVC’s model binding now uses IHttpRequestBodyDetectionFeature.CanHaveBody to decide whether a request can have a body. A body is only considered present if the HTTP request has the correct headers/flags, for example:
- For HTTP/1.x: a non‑zero
Content-Lengthheader orTransfer-Encoding: chunked. - For HTTP/2: the initial headers frame must not set the
END_STREAMflag.
If these conditions are not met, the framework treats the request as having an empty body and does not attempt deserialization. This can surface as intermittent “empty body” behavior if some requests from the Try It console are missing or mis‑setting these headers.
Recommended checks and actions:
- Inspect the actual HTTP requests sent from the Try It console (via browser dev tools or APIM inspector trace) and verify that:
-
Content-Lengthis present and non‑zero for requests with JSON or other payloads, or -
Transfer-Encoding: chunkedis set when appropriate.
-
- Ensure the backend API (for example, ASP.NET Core 7+ controllers) is receiving requests with the correct headers so
CanHaveBodyevaluates totruewhen a body is expected. - If using ASP.NET Core 7+, no code change is required in MVC itself; instead, ensure clients (including the Try It console) send the appropriate HTTP headers for requests with bodies.
If the Try It console is correctly sending bodies and headers, but the backend still sees empty bodies intermittently, use APIM inspector traces to confirm that APIM is forwarding the body unchanged and that no policies or intermediaries are stripping or altering Content-Length/Transfer-Encoding.
References: