Junior — Middle
What are the differences between GET and POST methods when sending requests in a browser?
sobes.tech AI
Answer from AI
GET and POST are two main methods of sending HTTP requests from a browser.
-
GET is used to request data from a server. Parameters are passed in the URL (query string), which limits their size and makes requests cacheable and bookmarkable. GET requests should be idempotent (not change server state).
-
POST is used to send data to a server, for example, when submitting forms. Data is sent in the request body, allowing larger volumes of data to be transmitted more securely. POST requests can modify server state.
Example:
GET /search?q=python HTTP/1.1
Host: example.com
POST /submit HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
name=John&age=30