415 Unsupported Media Type

The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.

Questions

Related Tags:
C# C# (pronounced "C-sharp") is an object-oriented programming language from Microsoft that aims to combine the computing power of C++ with the programming ease of Visual Basic. C# is based on C++ and contains features similar to those of Java. Learn More, React.js React (JavaScript library) In computing, React (also known as React.js or ReactJS) is a JavaScript library for building user interfaces. It is maintained by Facebook and a community of individual developers and companies. React can be used as a base in the development of single-page or mobile applications. Learn More, ASP.NET Core ASP.NET Core is a free and open-source web framework and successor to ASP.NET, developed by Microsoft. It is a modular framework that runs on both the full .NET Framework, on Windows, and the cross-platform .NET. However ASP.NET Core version 3 works only on .NET Core dropping support of the .NET Framework. Learn More, 415 Unsupported Media Type The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format. Learn More, HTTP response status codes HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Learn More,

Question:Getting 415 "Unsupported Media Type" on post request from reactjs to asp.net core apicontroller ?

Description:I am getting 415 "Unsupported Media Type" on a post request, my reactjs submit method looks like the following one where I am sending data using FormData handleEmployeeSubmit(employee) { const data = new FormData(); data.append('FirstName', employee.firstName); data.append('MiddleName', employee.middleName); data.append('LastName', employee.lastName); data.append('Designation', employee.designation); data.append('Salary', Number(employee.salary)); const xhr = new XMLHttpRequest(); xhr.open('post', this.props.submitUrl, true); xhr.onload = () => this.loadEmployeesFromServer(); xhr.send(data); } and my APIController method look like the following one [HttpPost] [Route("Create")] public async Task<ActionResult> create([FromBody] Employee employee) { int empid = await _employeerepository.Create(employee); return Ok(empid); } any help will be appreciated as I am new to both reactjs and .net core

View Details

Posted by: Emerging Expert | Posted on: May 13, 2022


1