Unsupported Media Type 415 in ASP.NET Core Web API

In this article, we will create a simulation to get a HTTP 415 "Unsupported Media Type" error.

- Create a new project


- Select ASP.NET Core Web Application


- Name the project


In the Create a new ASP.NET Core Web Application dialog, confirm that .NET Core and ASP.NET Core 3.1 are selected.

- Select the API template. Click Create.


In this way, you will create a new ASP.NET Core Web API Application

Create a new folder named Entities and then create a new class named Customer in the Entities folder as shown below.

using System.ComponentModel.DataAnnotations;

namespace WebApplication1.Entities
    public class Customer
        public int ID { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Address { get; set; }

- Add a new API controller named CustomerController in the Controllers folder.


- Add the following code snippet to the CustomerController.cs file

using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using WebApplication1.Entities;

namespace WebApplication1.Controllers
    public class CustomerController : ControllerBase
        private static List<Customer> customers = new List<Customer>
            new Customer { ID = 1, FirstName = "Judy", LastName = "Fortensky", Address = "Pennsylvania" },
            new Customer { ID = 2, FirstName = "Sara", LastName = "Garland", Address = "San Francisco" },
            new Customer { ID = 3, FirstName = "Gene", LastName = "Taylor", Address = "San Francisco" },
            new Customer { ID = 4, FirstName = "Larry", LastName = "Kelly", Address = "San Francisco" }

        public IActionResult Post([FromBody] Customer customer)
            int pID = customers[customers.Count - 1].ID + 1;
            customer.ID = pID;

            return CreatedAtRoute("CustomerById", new { id = customer.ID }, customer);

        [HttpGet("{id}", Name = "CustomerById")]
        public IActionResult Get(int id)
            Customer customer = customers.Find(x => x.ID == id);
            return Ok(customer);

- Start the project ans test the project with POSTMAN

After running the application, we will get a screenshot as follows


415 Unsupported Media Type

In the body request, we are sending an invalid JSON. We don't set content type right in the header.

To solve it, Click in Text and select the JSON option from the drop-down list. Then add the open and closed braces as shown below.


We received an HTTP 400 code. Because we didn't submit a customer object to the API.

Now let's see what happens after submitting the customer object



We received an HTTP 201 code. It works fine.

Download the source code.