Middle
How does a GET request differ from a POST request?
sobes.tech AI
Answer from AI
GET and POST methods are two main HTTP methods that differ in purpose and data transmission method.
- GET is used to request data from the server. All parameters are transmitted in the URL (in the query string), which limits the amount of data and makes requests cacheable and bookmarkable.
- POST is used to send data to the server, for example, when filling out forms. Data is transmitted in the request body, allowing for larger volumes and more sensitive information.
Main differences:
- GET is idempotent and safe, should not change the server state.
- POST can change the server state (create, update data).
- GET requests are visible in the URL, POST requests are not.
Example of a GET request:
GET /search?q=example HTTP/1.1
Host: example.com
Example of a POST request:
POST /submit HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
name=John&age=30