Junior — Middle
How do HTTP GET and POST methods differ in the context of data transmission and their usage?.
sobes.tech AI
Answer from AI
HTTP methods GET and POST differ in how they transmit data and their purpose:
-
GET transmits data via the URL (in the query string), typically used for retrieving data. Data is visible in the address bar, there are limitations on URL length, and requests can be cached and stored in browser history.
-
POST transmits data in the request body, used for sending data to the server (e.g., forms, file uploads). Data is not visible in the URL, there are no size limitations, and requests are not cached by default.
Example in Python using requests:
import requests
# GET request with parameters in URL
response = requests.get('https://example.com/api', params={'key': 'value'})
# POST request with data in the body
response = requests.post('https://example.com/api', data={'key': 'value'})