New in 2.4: Test runs you can trust See what's new →

Detects a body's real type from its content and compares it with the declared Content-Type

POSTPUTPATCHhttps://api.testingapis.com/api/bodies/any

Accepts POST, PUT and PATCH, up to 10MB. Recognises PNG, JPEG, GIF, PDF, ZIP and gzip by magic bytes, then JSON, HTML, XML, URL-encoded form, multipart and plain text; anything else is application/octet-stream.

Request body

Optional. application/octet-stream, application/json. Any body; the real type is detected and compared with Content-Type.

Example body
{"hello": "world"}

Responses

200
Declared and detected types, length and SHA-256.
413
Body larger than 10MB.

Example

Request
curl -X POST "https://api.testingapis.com/api/bodies/any" \
  -H "Content-Type: application/json" \
  -d '{"hello": "world"}'
Run in Studio
Response200 OK
{
  "method": "POST",
  "declaredContentType": "application/json",
  "detectedType": "application/json",
  "matchesDeclared": true,
  "length": 18,
  "sha256": "5f8f04f6a3a892aaabbddb6cf273894493773960d4a325b105fee46eef4304f1"
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/bodies/any", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: "{\"hello\": \"world\"}",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/bodies/any",
    headers={
        "Content-Type": "application/json",
    },
    data="{\"hello\": \"world\"}".encode("utf-8"),
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/bodies/any"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("{\"hello\": \"world\"}"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}