Request Parameters
Besides the URI and headers, a request message can contain additional information in the form of parameters. If the URI identifies a server-side program for displaying weather information, for example, request parameters can provide information about the city the user wants to see a forecast for. In an e-commerce application, the URI may identify a program that processes orders, with the user’s customer number and the list of items to be purchased transferred as parameters.
Parameters can be sent in one of two ways: tacked on to the URI in the form of a query string or sent as part of the request message body. This is an example of a URL with a query string:
http://www.weather.com/forecast?city=Hermosa+Beach&state=CA
The query string starts with a question mark (?)
and consists of name/value pairs separated by ampersands
(&). These names and values must be
URL-encoded
,
meaning that special characters, such as whitespace, question marks,
ampersands, and all other nonalphanumeric characters are encoded so
that they don’t get confused with characters used to
separate name/value pairs and other parts of the URI. In this
example, the space between Hermosa and
Beach is encoded as a plus sign. Other special
characters are encoded as their corresponding hexadecimal ASCII
value; for instance, a question mark is encoded as
%3F. When parameters are sent as part of the
request body, they follow the same syntax; URL encoded name/value
pairs separated by ampersands.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access