4xx Client errors
Last updated Mar 25, 2025

What is HTTP Status Code 451? - Unavailable for Legal Reasons

Nicolas Rios
Get your free
API key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

Typos can certainly lead to unexpected results. Not too long ago, we published an article on the HTTP 451 status code (‘Unavailable for Legal Reasons’), which unexpectedly included everything from hardcore programming to references to Ray Bradbury's work. It was a great article—just the topic, not what we intended to write about at the time. 

The article has since been updated to provide information on HTTP 415, as it should have from the start. While there are no bookish anecdotes in this version, it offers a comprehensive explanation of the HTTP 415 Unsupported Media Type error, its causes, implications, and, most importantly, the solutions that can be used to resolve it.

What is the HTTP 415 Unsupported Media Type Error?

Like many in the 21st century, you've likely encountered the HTTP 415 Unsupported Media Type status code. This HTTP status code is typically issued by a server in response to a client’s request, indicating that the server refuses to process it because the request’s media type is not supported by the server or the resource.

In such cases, the server explicitly rejects the request, because its Content-Type header doesn’t match what the server can process. To identify a request’s content, the server parses its Content-Type header. If it doesn’t align with the server’s expectations, the server issues a 415 status code and rejects the call.

Let’s say, for instance, that the server expects the Content-Type header to specify a JSON object (Content-Type: application/json) but the client sends XML instead (Content-Type: application/xml). After parsing it, the server will recognize that the content isn't in a format it can process and reject the request.

The 415 Unsupported Media Type error is part of the 4xx HTTP status code series, which signifies client-side errors. In other words, the issue lies with the client’s request, not the server. The problem occurs because the content is not supported by the server, or the Content-Type header is not correctly specified.

In most cases, this error is unintentional and simply indicates a mismatch between the client's and server's understanding of the data format. It can be typically solved by adjusting the client request to a format the server supports or configuring the server to accept a wider range of content types. 

Causes of HTTP 415 Errors

At its core, an HTTP 415 status code arises from a mismatch between the client and server regarding the Content-Type or Content-Encoding formats. This discrepancy between the server's and client's expectations can result in several causes for 415 errors, including:

  • Incorrect Content-Type Header: Including the wrong Content-Type header in the request can prevent the server from processing it, even when the content itself is supported by it. For example, if the header reads text/plain when the server expects application/json, the request won’t be processed.
Incorrect Content-Type Header
  • Unsupported media type: Some servers are configured to process only specific media types, which means any alternative content type specified in the Content-Type header will be rejected. For instance, sending an application/vnd.exotic-format content to a server that only supports application/json and application/xml objects is a guaranteed way to trigger an HTTP 415 error.
Unsupported media type
  • Missing header: When the client forgets to send the Content-Type header altogether, the server can be unsure about the format of the request body and refuse to process it, returning a HTTP 415 status code. However, this is not always the case, as some servers might assume a default format (such as application/octet-stream or application/x-www-form-urlencoded).
Missing header - Abstract API
  • Mismatched encoding: HTTP 415 errors can be triggered if the server doesn’t support or expect the encoding used by the client (e.g., gzip, compress, deflate), which is specified in the Content-Encoding header. The solution, in such cases, is either to remove the header or to configure the server to handle the specified encoding.
Mismatched encoding - Abstract API

It’s important to identify the cause of an HTTP 415 error promptly to resolve it before it disrupts workflow or affects overall software performance. The negative consequences can be significant, impacting both users and systems alike.

Impact of HTTP 415 Errors on Users and Applications

When not properly managed, HTTP 415 errors affect more than just the success of an operation. Unsupported Media Type errors can strain API integrations, lead to data loss, and hinder software functionality, all of which result in poor user experience and place a burden on developers.

More specifically, the negative impact of HTTP 415 errors on users and systems includes the following:

  • API integration and request: 415 errors are a common cause of API requests failure. Mismatches in content type (either in the headers or request body) can break API integration, as client and server need compatible media types to communicate. This can become particularly challenging in microservices architecture, when failure in one service can disrupt the entire system.
  • Broken functionality: Applications relying on specific media format for uploads, submissions, or API interactions are vulnerable to HTTP 415 errors. Unsupported content types jeopardize functionality, causing specific features or services to malfunction or fail. Eventually, this can damage the application’s reliability and reputation.
  • Data loss: At its core, an HTTP 415 error prevents a client’s request from successfully reaching the server. When the intended payload isn’t delivered, data may be lost. This impacts user trust, especially if users are forced to re-send requests. Additionally, it can become a critical issue in contexts such as financial transactions, database updates, or user submissions.
  • Poor user experience: HTTP 451 errors can be particularly frustrating for users. If not handled gracefully, users may not understand why their request fails, leading to dissatisfaction, loss of trust in the app, and even service abandonment. While 415 errors are caused by the client, it is ultimately the developer's responsibility to provide clear, comprehensive guidance that helps users navigate and resolve these issues.

In brief, properly handling media types is crucial for the successful implementation of APIs and other software services. Failure to manage these issues effectively can lead to a snowball effect, eventually resulting in serious consequences for both API users and developers.

How to Solve HTTP 415 Errors?

Communication failures between client and server due to unsupported media types can have serious consequences if not addressed promptly. Disruptions in business operations, particularly, make it essential to handle HTTP 415 errors efficiently and without delay.

While prevention is always preferable, mistakes can still occur. Therefore, understanding how to resolve HTTP 415 errors—both on the client and server sides—is essential knowledge that every software developer and user should possess. 

Let’s break down key strategies that will help you maximize your application’s functionality, gracefully handling HTTP 415 status codes.

Client-Side Solutions

Strategies to resolve HTTP 415 errors can be implemented on either the client or server side. Server-side approaches typically involve adjusting media type processing settings or issuing informative messages with practical steps. On the other hand, client-side solutions focus on tailoring requests to comply with server requirements. 

Common client-side approaches include verifying supported media-types, configuring content-type headers correctly, and ensuring the use of supported encoding.

Ready to put these strategies into action? In the following section, you'll find actionable steps for applying these measures and ensuring the smooth resolution of HTTP 415 errors.

Set the Correct Media Type

The first strategy one should apply from the client-side when facing a HTTP 415 status code is ensuring that the Content-Type header in the request is set to the correct and supported media type.

To successfully configure the Content-Type header you can follow these steps:

  1. Examine API documentation. Before making a request, check the API documentation to determine which media types the server can handle. These are often specified as application/json, application/xml, or multipart/form-data, among other formats.
  2. Set the correct Content-Type header. Configure the header to match the format of the data you are sending in the request, ensuring it complies with the server’s requirements and is properly formatted. 

For example, for JSON data, the header should read: Content-Type: application/json. If you're using JavaScript, you can configure the request's header using the Fetch API with the following script:

Content-Type: application/json - Abstract API

In this script, the headers parameter explicitly sets the Content-Type to application/json.

  1. Automatically configure Content-Type. Libraries and frameworks such as Axios or Fetch (when used for JSON) automatically set the Content-Type header to match the request body data. This helps minimize the likelihood of encountering HTTP 415 errors.
  2. Handle server response. Mistakes happen, even with the best intentions. If you receive an HTTP 415 status code or an error message related to Content-Type after submitting your request, don't panic…

…Instead, follow any instructions in the message (if provided) and carefully review the request. Also, ensure that both the header and body match and are compatible with what the server can process—our next client-side solution will fit like a glove for this—.

Verify Supported Media Types

Regardless of how perfectly formatted your request body and headers are, they will all amount to nothing if the media type you’re sending can’t be processed by the server. That’s why verifying supported media types is essential when dealing with HTTP 415 errors.

  1. The first and simplest step to determine which media types will successfully reach the server and be processed is to check the API documentation or, in some cases, the server’s configuration.
    1. Most API documentation does not only detail which media types and formats are supported, but also specifies the expected Content-Type for different types of requests (e.g., PUT, POST) and responses.
    2. To better navigate API documentation, look for sections such as Content-Type, Request Format, or Request Headers. These sections typically provide the information you need, along with examples of properly configured HTTP requests and response types.
  2. Another strategy for verifying supported media types is using the HTTP OPTIONS method, which is featured by some APIs. By sending an OPTIONS request, the server will respond with the media types and HTTP methods it accepts. 
    1. For example, the following script includes an OPTIONS request issued with the curl command:
script includes an OPTIONS - Abstract API
  1. Here, you’ll see the server’s response, which includes the media types the API accepts (under the Accept header),  and the supported HTTP methods (under the Allow header).
  1. If neither of these strategies works, perhaps the third time’s the charm. Another option for verifying supported media types—if you have access to the server or its configuration—is to examine the backend code. By reviewing the server’s request-handling logic, you may find details on the media formats it accepts.
    1. Start by checking how the Content-Type header is validated, which ensures incoming requests match the expected format. In Node.js (Express), it might look like this:

In this example, the server checks if the request’s header is application/json before processing the data.

  1. If the results are not conclusive, inspect the server’s request handlers. Look for functions such as json() or urlencoded() that specify which media types the server can handle. You can also find these configurations in the API’s middleware.
  2. For servers built with strongly-typed languages like Java or C#, look for attributes such as Consumes("application/json") or annotations like @Consumes. These are typically used to define which media types are expected by the server.

Use a Supported Encoding

Finally, client-side solutions to HTTP 415 errors include ensuring the data is encrypted using a supported encoding. This can be key when the server expects a particular encoding format, such as UTF-8.

In a request, the encoding format is specified through both the Content-Type and charset. Text-based content like XML, JSON, and form data is commonly encoded using UTF-8 encoding. Therefore, most APIs and servers will expect this encoding.

To ensure requests’ encoding is supported, follow these steps:

  1. Specify charset in content-type. When issuing a request, make sure to specify the encoding within the content-type header, using the charset directive. For JSON data and UTF-8 encoding, for instance, the script should read application/json; charset=UTF-8.
  2. Encode the data. Although most libraries and modern programming languages encode in UTF-8 by default, it is advisable to set the encoding explicitly to ensure data is correctly encoded.
    1. Step (1) is enough to guarantee that data is encoded when using JavaScript. Here, JSON.stringify() will automatically encode the data in UTF-8, once charset is specified.
JSON.stringify() - Abstract API
  1. However, in Python, use the json.dumps() function to serialize data to a JSON-encoded string.
json.dumps() - Abstract API

Server-Side Solutions

As mentioned earlier, server-side approaches to handling HTTP 415 Unsupported Media Type status codes involve both informing users about how to resolve 415 errors and adjusting the server to meet user requirements.

Now, let’s explore some common server-side solutions that can effectively resolve most HTTP 415 issues.

Support Necessary Media Types

Configuring your server to accept, process, and respond with the media types used by clients—especially those that might trigger HTTP 415 errors—is essential for ensuring seamless communication between client and server. This configuration not only enhances functionality but also improves versatility and user experience.

Media types are typically defined in HTTP headers. For instance, in a REST API, you would use the Content-Type and Accept headers. The first header specifies the media type of the request body, while the second header indicates the media types the client will expect in the response.

To expand media type support in various frameworks, consider the following:

  • Python (Flask): By default, this framework handles JSON requests. However, to support custom formats, you need to add logic for parsing and processing the request body.

In the example below, Flask supports both application/json and application/xml by using Python's xml.etree.ElementTree (ET) for XML parsing.

Python's xml.etree.ElementTree (ET)

The server determines whether it should parse the body with Flask's built-in .json property or ET based on the Content-Type header. Unsupported media types will trigger an HTTP 415 error.

  • Java (Spring Boot): This framework natively supports multiple media types, including JSON and XML. To specify which media types your application will handle, you’ll have to list them in the @Consumes and @Produces annotations:
Java (Spring Boot) - Abstract API

On the other hand, in the example below the @PostMapping annotation is used to configure the /submit endpoint to support both JSON and XML inputs. If the server receives a media type not listed in the @Consumes annotation, it will return a message saying ‘Unsupported media type’ and reject the request.

@PostMapping - Abstract API

Provide Clear Error Messages

Server-side solutions for managing HTTP 415 errors also require providing clear and informative error messages to help clients understand the issue and how to resolve it. Detailed error messages including recommended steps, enable faster debugging, improve user experience, fostering trust in your API.

Ideally, error messages should address the following points:

  • Status code: Clearly state that the client is facing an HTTP 415 error and briefly describe the issue (i.e., Unsupported media type).
  • Provided media type: Specify the content type sent by the client.
  • Supported media types: List the accepted media formats to help the client adjust their request.
  • Actionable steps: Include instructions on how to resolve the HTTP 415 error. Optionally, provide a link to documentation for further troubleshooting.

To implement an informative and straightforward error response in Python (Flask) you can use the following script, which mirrors the structure of a typical Node.js implementation:

Provide Clear Error Messages - Abstract API

Implement Content Negotiation

Content negotiation is an essential mechanism for reducing the likelihood of HTTP 415 errors, as it enables the server to choose between different response formats based on what the client can handle. This ensures seamless integration and preserves functionality. 

As a result, APIs that properly implement content-type negotiation are generally more reliable and user-friendly, and less prone to HTTP 415 errors, compared to those that do not. 

Typically, content negotiation is supported by RESTful APIs (Abstract’s mainstay), and frameworks such as Node.js (Express), Django REST, Flask (Python), and Spring Boot (Java). 

To apply it, the server inspects the Accept header in the client’s request. This header lists the media types supported by the client, allowing the server to select the most appropriate one.

Once the server has determined which media type will provide the best match, it responds to the client using the appropriate Content-Type header:

However, if the Accept header specifies a media type that the server does not support, or if the client omits the  Accept header entirely, the server will typically reply in a default format, such as application/json.

To apply content negotiation in a Flask application, you can use the following script:

apply content negotiation in a Flask application

With this script, the server will examine the Accept header and respond using either the appropriate content format or a 406 Not Acceptable error.

Preventing HTTP 415 Errors

When dealing with HTTP 415 errors, prevention is essential. As we mentioned before, unsupported media types can negatively impact user trust and app functionality, even if resolved quickly. 

On the contrary, by preventing HTTP 415 errors, you ensure that APIs integrate seamlessly, reducing the risk of broken workflows and preserving application performance. This not only enhances the user experience but also prevents data loss and lowers support costs.

In short: prevention is key. Hence, let’s review some best practices to help you avoid HTTP 415 errors.

Clear Documentation

In our experience, providing accessible and easy-to-understand documentation works wonders in preventing HTTP 415 errors.

Similar to error messages, comprehensive documentation ensures that API developers and users have clear information on the API’s supported media types and Content-Type header requirements. This makes it easier for users to internalize the correct ways to interact with the API, structure requests properly, and know which media types are supported.

However, it’s crucial that Content-Type header requirements and supported media types are thoroughly documented to help users handle specific HTTP error codes more effectively. For example, at Abstract, our API documentation related to HTTP 415 typically:

  • Specifies the purpose of the Content-Type header in API requests, explaining its role in data transmission and how to configure it to match the request body format.
  • Lists the exact Content-Type values accepted by the API, pinpointing media types for specific API endpoints (e.g. multipart/form-data for file uploads and JSON for data submissions).
  • Clarifies which media types are not supported, to avoid ambiguity and unintentional mistakes. Additionally, it outlines which API versions (if applicable) support which media types, preventing confusion.
  • Features examples of API requests for each supported media type, demonstrating the correct Content-Type header and body format in different programming languages where necessary.
  • Highlights examples of relevant endpoints with different content formats, including both the Content-Type header and the corresponding body structure.
  • Describes how the server handles incorrect Content-Type headers and unsupported media types are handled by the server, including examples of the HTTP 415 status code and the error responses returned by the API.
  • Offers actionable feedback to correct flawed requests, expanding on the solutions provided in error messages and addressing more complex cases that require detailed guidance.
  • Includes information on content negotiation for APIs that support it, explaining how developers can configure their requests to handle different media types.

While it's not mandatory to organize documentation this way, this approach has proven to be one of the most effective we've used. It consistently delivers solid results and significantly enhances workflow and communication between clients and servers. However, keep in mind that the best strategy will always be adjusting your documentation to your client’s needs!

Input Validation on Server-Side

Of course, not every user will read the API documentation before starting to interact with an API (as advisable as it may be). Therefore, a key preventive measure for managing HTTP 415 errors is implementing input validation on the server side. 

Server-side validation consists of corroborating the request body and Content-Type header display supported media types, before the request is fully processed. This helps reduce confusion for API users, as unsupported media types are detected early

Thus, server-side validation minimizes the need to handle errors on the client side, leading to a more streamlined workflow and more reliable API behavior by ensuring uniform request processing. Additionally, it enhances API security by protecting the server from suspicious or potentially malicious data formats.

To successfully implement server-side validation, you can follow these steps:

  1. First, configure the server to validate the Content-Type header in an incoming request. Set it to check if the Content-Type header value matches one of the media types the API server supports. If the media format is unsupported, it should return an HTTP 415 status code

For example, in Node.js (Express), you can run the following code:

  1. The second step for input validation is corroborating that the request body is properly structured, according to the media type specified on the Content-Type header. Different content formats require different checks. For example, JSON data can be validated using the following script in Node.js (Express):
 JSON data can be validated using the following script in Node.js (Express)

However, for validating XML requests in Node.js (Express), the script used should read as it follows:

XML requests in Node.js (Express)
  1. Return clear, informative messages for invalid Content-Type headers or a request body with an unsupported media type. Remember to clearly state the client’s mistake and to suggest how they can fix it..
  2. On the other hand, for multipart/form-data requests, used for file uploads, proper validation requires verifying that the necessary form fields are included on the message, and that the files fit the expected type and size. To achieve this:
    1. Parse the form data. In Node.js, you can use a library like multer
    2. Verify compliance with required fields and file types.
    3. Return an HTTP error if the body is missing expected data, the file is too large, or there’s a media type mismatch.

With Node.js (Express) you can configure the server to follow the previous steps with this code:

With Node.js (Express) you can configure the server

Content Negotiation

Content negotiation is a flexible solution to HTTP 415 errors. It can be used both for fixing 415 errors on the go, and to thoroughly prevent them, by handling different client preferences for media types. 

In other words, content negotiation allows the server to adjust its responses’ format to the client’s, greatly improving user experience and the APIs’ interoperability, making it more suitable for complex use cases. For example, a microservices API that returns data using different formats according to the client’s needs, or APIs that support various content types.

flexible solution to HTTP 415 errors

As we’ve already reviewed how to implement content negotiation, let’s discuss some best practices you can apply to achieve quality results: 

  1. Always check the Accept header, since that's where the client will specify the media type of its preference. For example, if the client prefers JSON, it might read:

If the client can accept multiple media types, it will specify them in  Accept, in most cases including quality values (q-values) to pinpoint which content formats are preferred:

  1. Provide a default media type (like application/json), to further prevent HTTP 415 errors when the client doesn’t include the Accept header, or uses a wildcard (*/*).
  2. When returning error messages (such as 406 Not Acceptable) remember to guide the content formats your API supports.

These practices will help you strengthen HTTP 415 prevention, ensuring seamless communication and streamlining workflows.

Properly Testing API Endpoints

Finally, thoroughly testing API endpoints with different Content-Type headers plays a key part in ensuring requests are handled correctly by the server, in various scenarios.

To evaluate how API endpoints function with specific media types, you’ll have to define the supported media types your API will accept, and set up a testing environment. Consider using the following tools:

  • pytest/requests (Python): Use it with APIs built with Python frameworks, such as Django or Flask.
  • Postman: It helps you create and run automated tests, with different case scenarios.
  • JUnit/Mockito (Java): You can use this tool to write tests in Spring Boot.
  • cRUL: Manually tests endpoints, using command-line requests.

Testing API endpoints requires that you define several case scenarios for different media types, with both valid and invalid Content-Type headers, to ensure proper error handling. For each test case, you should specify

  • Input.
  • Expected output.
  • Request method.
  • Expected HTTP status code.

Postman and cURL, among other tools, allow you to perform manual API tests without having to write scripts. However, automated testing and complex scenarios require scripts. For example, to test API endpoints in Python, using requests and pytest, you can run the following code:

Test API endpoints in Python, using requests and pytest

Some common case scenarios you should consider for testing API endpoints include:

  • Supported Content-Types: Verify that the server accepts all of them, returning the specified results.
  • Unsupported Content-Types: Ensure that the server returns an HTTP 415 status code.
  • Missing Content-Types: The server should respond either with a default response or with a 415 error code, when the  Content-Types header is not specified.
  • Edge cases: Confirm that your API is robustly configured by testing unusual or malformed Content-Type headers.
  • Request methods: Content validation and (if applicable) negotiation should work for general HTTP methods, including GET, POST, PUT, and DELETE.

Navigating HTTP 415

In Abstract API we know that HTTP 415 errors can be a significant setback if not properly handled. These errors indicate an unsupported media type, meaning that when a 415 status code is issued, communication between the client and server is disrupted, undermining API functionality and users' workflows.

However, these errors can be easily prevented with the right strategies, such as using the correct Content-Type header and implementing content negotiation. These approaches can be applied to both the server and content sides, ensuring HTTP 415 errors are handled efficiently.

To navigate through HTTP 415  errors with ease, API documentation is an invaluable resource, offering guidance on how to handle HTTP issues specific to an API, as well as best practices for achieving quality results and building robust APIs that are simple to implement and interact with.

Explore our documentation to discover an extensive catalog of API-related knowledge that every software developer and user should know to build better, faster, and more reliable APIs. Don't get lost in the programming sea—navigate the best routes with us!

Get your free
API
key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required