Java Reference
In-Depth Information
The above URL specifies a path of “ /1/1/cities.php ”.
Parameters can be passed using the query portion of the URL. The following URL dem-
onstrates this idea.
http://www.httprecipes.com/1/1/city.php?city=2
The above URL passes one parameter using the query string. A parameter named “city”
is passed to the query string. The parameter “city” has the value of “2”. It is also possible to
pass multiple parameters. If you would like to pass multiple parameters, they should be sepa-
rated by the ampersand symbol (&). The following URL makes use of the ampersand to pass
in two parameters. These two parameters are named “city” and “zip code”.
http://www.httprecipes.com/1/1/city.php?city=2&zipcode=63017
So far the URLs we have examined all contain standard ASCII (American Standard Code
for Information Interchange) letters and numbers. In the next section, you will see how to
encode special characters into the URL.
Encoding Special Characters into a URL
URLs can contain a wide variety of characters; however, there are only certain characters
that you can put directly into a URL. For example, you cannot put a space into a URL. If you
wanted to pass the value “John Smith” to the variable “name”, you could not construct a URL
such as:
http://www.httprecipes.com/1/test.php?name=John Smith
The above URL is invalid because spaces are not allowed in a URL. To put a space into a
URL, express the URL as follows:
http://www.httprecipes.com/1/test.php?name=John%20Smith
As you can see, the above URL contains the characters “%20” where the space is. This
is because a space is ASCII code 32. The decimal number “32” is “20” in hexadecimal. Any
ASCII code, from 0 (hexadecimal 0) to 255 (hexadecimal FF) can be represented this way.
The space character, however, is special. It also has a second way that it can be repre-
sented. Spaces can be represented with the plus (+) character. Therefore, it would also be
valid to represent the above URL as:
http://www.httprecipes.com/1/test.php?name=John+Smith
Search WWH ::




Custom Search