Java Reference
In-Depth Information
C HAPTER 3: S IMPLE R EQUESTS
• Using the URL Class
• Downloading a Page
• Downloading an Image
• Parsing Data
The purpose of the HTTP protocol is to exchange information between an HTTP server
and an HTTP client. Usually the HTTP client is a user with a web browser; however, this is
not always the case. Sometimes, the HTTP client is actually a program using the web. Java
provides many classes that allow Java programs to make use of web pages. In this chapter,
these classes will be introduced.
The concept of a web page is very important. Information that you would like to access,
using HTTP, will be on a specific web page. The web browsing experience is based on many
different web pages. For example, every time a link is clicked, the browser usually moves to
a new web page. Likewise, the information you would like to access, using HTTP program-
ming, is on such a page.
Each of these pages has a unique address, which is used to identify that page. This ad-
dress is the Uniform Resource Locater (URL). The quickest way to find the URL of your
“page of interest”, is to navigate directly to that page with a web browser. The web browser's
address line will show the address of the desired page.
As seen in Figure 3.1, the browser is currently at the URL address of
http://www.httprecipes.com/1/3/time.php . If you wanted to collect data from
this web page, you would use this URL.
 
Search WWH ::




Custom Search