17.4. Example: A Network Client That Retrieves URLs

Retrieving a document through HTTP is remarkably simple. You open a connection to the HTTP port of the machine hosting the page, send the string GET followed by the address of the document, followed by the string HTTP/1.0, followed by a blank line (at least one blank space is required between GET and address, and between address and HTTP). You then read the result one line at a time. Reading a line at a time was not safe with the mail client of Section 17.3 because the server sent an indeterminate number of lines but kept the connection open. Here, however, a readLine is safe because the server closes the connection when done, yielding null as the return value of readLine.

Although quite simple, ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.