Coding⏱️ 3 min read📅 2026-06-04

How to Fix: Request failed: unacceptable content-type: text/html using AFNetworking 2.0

Learn how to easily fix and troubleshoot How to Fix: Request failed: unacceptable content-type: text/html using AFNetworking 2.0 with our step-by-step

Quick Answer: 1-2 sentences of direct conversational advice.

The error 'Request failed: unacceptable content-type: text/html' occurs when AFNetworking attempts to parse an HTML response as JSON.

This issue affects users who are trying to retrieve data from APIs that return HTML responses. To resolve this, ensure that the API endpoint being called returns a valid JSON response.

We will provide two alternative methods for fixing this error and explain each in detail below.

⚠️ Common Causes

  • The primary cause of this error is due to AFNetworking's inability to recognize HTML responses as JSON.
  • This limitation can be circumvented by using the `responseSerializer` property to specify a custom response serializer that can handle both JSON and HTML responses.

🔧 Proven Troubleshooting Steps

Using a Custom Response Serializer

  1. Step 1: Create a custom class that conforms to the `AFJSONResponseSerializer` protocol.
  2. Step 2: Override the `responseClass` property to return an instance of your custom class.
  3. Step 3: In the `responseSerializer` property, set your custom class as the response serializer for AFNetworking.
  4. Step 4: Example code:`,objectivec', self.responseSerializer = [YourCustomResponseSerializer serializer];'`,

Using a Third-Party Library

  1. Step 1: Install the `AFNetworking Plus` library, which provides additional features and functionality for handling HTML responses.
  2. Step 2: Import the library in your project and use its `AFJSONResponseSerializerPlus` class to handle HTML responses.
  3. Step 3: Example code:`,objectivec', import ';', ' AFJSONResponseSerializerPlus *serializer = [AFJSONResponseSerializerPlus serializer];', ' self.responseSerializer = serializer;'`,

🎯 Final Words

By following these steps, you should be able to resolve the 'Request failed: unacceptable content-type: text/html' error and retrieve data from APIs that return HTML responses.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions