```yaml
product: AlterLab
title: "Content-Type — Web Scraping Glossary | AlterLab"
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
source_url: https://alterlab.io/glossary/content-type
```

protocol

# Content-Type

The Content-Type HTTP header describes the media type and encoding of a request or response body, telling the recipient how to parse the payload.

Content-Type is one of the most important HTTP headers for scrapers. In responses, it tells the scraper how to interpret the body: `text/html; charset=utf-8` (HTML document), `application/json` (JSON payload), `application/octet-stream` (binary data), `text/csv` (CSV file), or `application/pdf` (PDF document). The charset parameter specifies the character encoding; mismatched encoding causes garbled text extraction.

In POST requests, Content-Type tells the server how to parse the request body: `application/x-www-form-urlencoded` (HTML form submission), `multipart/form-data` (file uploads), or `application/json` (API call with JSON body). Sending the wrong Content-Type for a POST will often result in a 400 Bad Request error because the server cannot parse the body correctly.

For API discovery, checking whether a URL returns `application/json` when scraped reveals undocumented API endpoints that power the site's frontend — a more reliable data source than HTML parsing.

### What is Content-Type?

The Content-Type HTTP header describes the media type and encoding of a request or response body, telling the recipient how to parse the payload.

### How does AlterLab handle Content-Type?

For API discovery, checking whether a URL returns `application/json` when scraped reveals undocumented API endpoints that power the site's frontend — a more reliable data source than HTML parsing.

## Examples

```
import requests

response = requests.get("https://example.com/api/products")
content_type = response.headers.get("Content-Type", "")

if "application/json" in content_type:
    data = response.json()
elif "text/html" in content_type:
    # Parse HTML
    pass
else:
    print(f"Unknown content type: {content_type}")
```

## Related Terms

[HTTP HeadersKey-value metadata fields sent with HTTP requests and responses that communicate authentication, content type, caching, and other directives.](https://alterlab.io/glossary/http-headers)[HTTPHTTP (HyperText Transfer Protocol) is the application-layer protocol used by web browsers and scrapers to request and receive resources from web servers.](https://alterlab.io/glossary/http)[REST APIA web service that exposes data and actions through standard HTTP methods and resource-oriented URLs, returning structured JSON responses.](https://alterlab.io/glossary/rest-api)[JSONJavaScript Object Notation — the universal text format for structured data exchange between APIs and web services.](https://alterlab.io/glossary/json)[Content NegotiationContent negotiation is an HTTP mechanism where the client specifies preferred response formats (JSON, HTML, XML) via Accept headers and the server responds in the best matching format.](https://alterlab.io/glossary/content-negotiation)

## Extract Content-Type data from any website

AlterLab returns clean, structured data from any public URL — no scraper infrastructure needed. Start free, no credit card required.

[View API docs](https://alterlab.io/docs/api/rest)

[Back to Glossary](https://alterlab.io/glossary)