68 / 80 · 12 Programming for QA · HTTP Fundamentals← prev⊞ allnext →☰ Read as one page
8.7Content Types
| Content-Type | Used For | Example |
|---|---|---|
application/json |
REST APIs | {"name": "Alice"} |
application/x-www-form-urlencoded |
HTML forms | name=Alice&email=alice@test.com |
multipart/form-data |
File uploads | Binary file data with boundaries |
text/html |
Web pages | HTML content |
application/xml |
SOAP APIs, legacy systems | <user><name>Alice</name></user> |
# Sending form data (not JSON)
r = requests.post(f"{base_url}/login", data={"username": "alice", "password": "pass123"})
# Uploading a file
with open("document.pdf", "rb") as f:
r = requests.post(f"{base_url}/upload", files={"file": f})