文章来源:
- URL url = new URL("http://127.0.0.1:8080/cfStruts2Ex2/");
- URLConnection urlConn = url.openConnection();
- System.out.println("Date: " + new Date(urlConn.getDate()));
- System.out.println("Content-Type: " + urlConn.getContentType());
- int length = urlConn.getContentLength();
- System.out.println("Content-Lentgth: " + length);
- if (length > 0) {
- System.out.println("========== Content ==========");
- InputStream input = urlConn.getInputStream();
- int i = length;
- int c;
- while ((c = input.read()) != -1 && --i > 0) {
- System.out.print((char) c);
- }
- input.close();
- } else {
- System.out.println("No Content.");
- }