fwr nr
fwr nr

Reputation: 697

Why do request parameters sent in request body need to be URL encoded?

I understand with GET request they need to be entered into a URL and therefore need to be URL (percent) encoded so that they don't mean anything in the context of a server interpreting the URL.

But if data is in the body of a request rather than the URL then why does it need to be URL encoded?

Example:

enter image description here

Upvotes: 14

Views: 9609

Answers (1)

Mahozad
Mahozad

Reputation: 24712

You can have any format you want in the body of a POST request. You should just make sure that the receiving end (server) accepts that format and knows how to handle that.

URL-encoding (application/x-www-form-urlencoded Content-Type) is frequently used because it is the default format of data when submitting an HTML <form> in web pages and because most servers know how to handle it.

So, as comments said, the data in your POST body need to be url-encoded because you/browser/agent have specified the HTTP Content-Type: application/x-www-form-urlencoded header.

Upvotes: 1

Related Questions