JamesGold
JamesGold

Reputation: 815

Why are query strings sent in the URL of a GET request and sent in the body of POST requests?

GET:

GET /blog/?name1=value1&name2=value2 HTTP/1.1
Host: website.com

POST:

POST /blog/ HTTP/1.1
Host: website.com
name1=value1&name2=value2

I don't see why there should be a difference.

Upvotes: 1

Views: 273

Answers (2)

Julian Reschke
Julian Reschke

Reputation: 42025

It's a result of how form submission is defined for HTML forms. It has nothing to do with HTTP itself.

Upvotes: 0

Octavia Togami
Octavia Togami

Reputation: 4306

GET is supposed to be used for bookmark-able pages or repeatable searches; so the URL stores the query data so it can be used repeatedly by the browser.

POST, on the other hand, is for one-time requests containing sensitive information or information that might be too long for a query string. The data isn't supposed to be saved like in a GET request, so it is stored in the body.

You might also want to see this SO answer: https://stackoverflow.com/a/198473/436524

Upvotes: 1

Related Questions