Junior — Middle
Can you name the main types of headers used in HTTP requests?
sobes.tech AI
Answer from AI
The main types of headers in HTTP requests can be divided into several categories:
-
General headers — apply to both requests and responses, for example:
Cache-Control— cache managementConnection— connection management
-
Request headers — transmit information about the client and request:
Host— specifies the server's domain nameUser-Agent— information about the client applicationAccept— data types the client is willing to acceptAuthorization— authentication dataCookie— session data
-
Entity headers — describe the message body:
Content-Type— content typeContent-Length— length of content
Example of using headers in Python with the requests library:
import requests
headers = {
'User-Agent': 'MyApp/1.0',
'Accept': 'application/json',
'Authorization': 'Bearer token123'
}
response = requests.get('https://api.example.com/data', headers=headers)
print(response.status_code)