Sobes.tech
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:

  1. General headers — apply to both requests and responses, for example:

    • Cache-Control — cache management
    • Connection — connection management
  2. Request headers — transmit information about the client and request:

    • Host — specifies the server's domain name
    • User-Agent — information about the client application
    • Accept — data types the client is willing to accept
    • Authorization — authentication data
    • Cookie — session data
  3. Entity headers — describe the message body:

    • Content-Type — content type
    • Content-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)
Can you name the main types of headers used in HTTP… - sobes.tech