- From: Mark Friedman <mark@intraspect.com>
- Date: Tue, 27 May 1997 10:43:48 -0700
- To: "Joseph M. Futrelle" <futrelle@ncsa.uiuc.edu>
- CC: www-jigsaw@w3.org
I have a problem and a question. First the problem. I get a
ClassCastException on the second line of the following fragment:
URL url = new URL (args[0]);
w3c.www.protocol.http.HttpURLConnection c =
(w3c.www.protocol.http.HttpURLConnection) url.openConnection();
when run with the following command line:
e:\jdk1.1.1\bin\java -classpath
.;c:\jigsaw-alpha5\jigsaw\classes\jigsaw.zip;e:\jdk1.1.1\lib\classes.zip
-Djava.handler.protol.pkgs=w3c.www.protocol httpURLTest
http://www.microsoft.com
where httpURLTest is shown at the end of this message.
My question is: How do you get the status code of an HttpURLConnection
or a URLconnection?
Thanks in advance.
-Mark
------------ httpURLTest.java -----------
import java.util.*;
import java.net.*;
import java.io.*; // FIXME - DEBUG
import w3c.www.protocol.http.*;
import w3c.www.mime.*;
import w3c.util.*;
public class httpURLTest {
public static void main(String args[]) {
try {
URL url = new URL (args[0]);
w3c.www.protocol.http.HttpURLConnection c =
(w3c.www.protocol.http.HttpURLConnection) url.openConnection();
// Display some infos:
System.out.println("last-modified: "+c.getLastModified());
System.out.println("length : "+c.getContentLength());
// System.out.println("status : "+c.getStatus());
System.out.println("location :
"+c.getHeaderField("location"));
// Display the returned body:
InputStream in = c.getInputStream();
byte buf[] = new byte[4096];
int cnt = 0;
while ((cnt = in.read(buf)) > 0)
System.out.print(new String(buf, 0, 0, cnt));
System.out.println("-");
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
System.exit(1);
}
}
Received on Tuesday, 27 May 1997 13:44:34 UTC