Junior — Middle
What is the role of headers in HTTP requests and why are they used?
sobes.tech AI
Answer from AI
Headers in HTTP requests contain metadata about the request itself or the client. They are used to transmit data that is not included in the request body, such as:
- Content-Type
- Authorization
- Browser information (User-Agent)
- Cookies
This allows the server to process the request correctly and understand the context.
Example of using a header in Python with requests:
import requests
headers = {'Authorization': 'Bearer token123'}
response = requests.get('https://api.example.com/data', headers=headers)