Other 4xx codes
All HTTP status codes in ASP.NET Core
4xx Client error
The server refuses the request body's format, given by its Content-Type header.
In ASP.NET Core: Sent when a JSON body arrives without Content-Type: application/json.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 415.
| Constant | StatusCodes.Status415UnsupportedMediaType |
|---|---|
| HttpStatusCode | HttpStatusCode.UnsupportedMediaType |
| Reason phrase | Kestrel sends Unsupported Media Type |
| Class | 4xx, client error |
| IsSuccessStatusCode | false |
| EnsureSuccessStatusCode() | throws HttpRequestException: Response status code does not indicate success: 415 (Unsupported Media Type). |
| Standard resilience handler | does not retry it |
Results.StatusCode(StatusCodes.Status415UnsupportedMediaType)
Results.Problem(statusCode: StatusCodes.Status415UnsupportedMediaType, detail: "...")StatusCode(StatusCodes.Status415UnsupportedMediaType)
Problem(statusCode: StatusCodes.Status415UnsupportedMediaType, detail: "...")What Results.Problem(statusCode: 415) sends (with AddProblemDetails()), as application/problem+json:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.16",
"title": "Unsupported Media Type",
"status": 415,
"traceId": "0HNA1B2C3D4E5:00000001"
}A controller's Problem(statusCode: 415) sends the same body.
A bare StatusCode(415) in an [ApiController] also gets a ProblemDetails body automatically; Results.StatusCode(415) in a minimal API sends an empty body unless you add UseStatusCodePages().
Setup
app.MapPost("/minimal", (Payload p) => p.Name);Request
POST /minimal HTTP/1.1
Content-Type: text/plain
{"name":"a"}Response (recorded)
HTTP/1.1 415 Unsupported Media TypeMinimal APIs only read a body parameter from a JSON Content-Type. text/plain is 415, with an empty body in Production.
Fix: Send Content-Type: application/json. With HttpClient, PostAsJsonAsync sets it; new StringContent(json) alone sends text/plain.
Setup
builder.Services.AddProblemDetails();
app.UseStatusCodePages();Request
POST /minimal HTTP/1.1
Content-Type: text/plainResponse (recorded)
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/problem+json
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.16",
"title": "Unsupported Media Type",
"status": 415,
"traceId": "0HNA1B2C3D4E5:00000001"
}With status code pages the client at least gets a ProblemDetails body naming the status.
Setup
[HttpPost]
public IActionResult Create(Thing t) => Ok(t);Request
POST /api/things HTTP/1.1
Content-Type: text/plain
{"name":"a"}Response (recorded)
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/problem+json; charset=utf-8
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.16",
"title": "Unsupported Media Type",
"status": 415,
"traceId": "0HNA1B2C3D4E5:00000001"
}No input formatter accepts text/plain, so MVC answers 415, as ProblemDetails because of [ApiController].
Every response on this page was recorded from ASP.NET Core 10.0.12 on Kestrel in the Production environment; the HttpClient rows come from .NET 10.0.12 and Microsoft.Extensions.Http.Resilience 10.10.0.
All HTTP status codes in ASP.NET Core