Java Reference
In-Depth Information
}
System . out . println ( contentLength );
int c ;
int i = 0 ;
while (( c = in . read ()) != - 1 && i ++ < length ) {
System . out . write ( c );
}
System . out . println ();
} catch ( IOException ex ) {
System . err . println ( ex );
} finally {
try {
if ( socket != null ) socket . close ();
} catch ( IOException e ) {}
}
}
}
Here are the first few lines of output from this program when you connect to the U.S.
Postal Service's website:
% java HTTPSClient www.usps.com
HTTP/1.1 200 OK
Server: IBM_HTTP_Server
Cache-Control: max-age=0
Expires: Sun, 31 Mar 2013 17:29:33 GMT
Content-Type: text/html
Date: Sun, 31 Mar 2013 18:00:14 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Connection: Transfer-Encoding
00004000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
When I tested this program for the previous edition, it initially re‐
fused to connect to www.usps.com because it couldn't verify the iden‐
tity of the remote server. The problem was that the root certificates
shipped with the version of the JDK I was using (1.4.2_02-b3) had
expired. Upgrading to the latest minor version (1.4.2_03-b2) fixed the
problem. If you see any exception messages like “No trusted certifi‐
cate found,” try upgrading to the latest minor version of the JDK.
When you run this program, you may notice that it's slower to respond than you expect.
There's a noticeable amount of both CPU and network overhead involved in generating
Search WWH ::




Custom Search