W3C home > Mailing lists > Public > www-jigsaw@w3.org > May to June 1997

HttpURLConnection [was Re: Handling of redirections (fwd)]

From: Mark Friedman <mark@intraspect.com>
Date: Tue, 27 May 1997 10:43:48 -0700
Message-ID: <338B1D54.E8B01800@intraspect.com>
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


      -Djava.handler.protol.pkgs=w3c.www.protocol httpURLTest

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.


------------ 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       :
      // 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));
 } catch (Exception ex) {
Received on Tuesday, 27 May 1997 13:44:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:26 GMT