Chapter 4: Data Formats 121
PART I
but if data sizes are large, the wordiness of the packaging format could be an important
consideration.
Now that we have mentioned each of the data format decisions that are important at a
high level, let’s examine the value of each particular format for Ajax applications in depth.
Standard Encoding: x-www-form-urlencoded
The standard format to encode data for transmission from client to server in Web applications
is the x-www-form-urlencoded format. The basic form of such data is a list of name-value
pairs separated by ampersand (&) characters. For example:
name1=value1&name2=value&name3=value3&...&nameN=valueN
The individual names and values are encoded as follows:
- Space characters are replaced by + symbols.
- Reserved characters such as nonalphanumeric characters that may be dangerous in
a URL are replaced by %HH where HH is two hexadecimal digits representing the
ASCII code of the replaced character (for example, the “?” character becomes %3F,
which corresponds to the decimal value 63, which is the ASCII value of the question
mark). - Line breaks are represented as CR LF pairs, which corresponds to the value '%0D%0A'.
- Reserved characters such as nonalphanumeric characters that may be dangerous in
A list of the common characters that are often encoded and their hex values can be
found in Table 4-1.
Character Encoded Value Character Encoded Value
/ %2F { %7B
? %3F } %7D
: %3A [ %5B
; %3B ] %5D
& %26 “ %22
@ %40 ` %27
= %3D ‘ %60
# %23 ^ %5E
% %25 ~ %7E
> %3E \ %5C
< %3C | %7C
( %28 ) %29
(space) %20 + %2B
! %21
TABLE 4-1 Common Encoded Characters with Hex Values