home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / net / HttpURLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.7 KB  |  113 lines

  1. package java.net;
  2.  
  3. import java.io.IOException;
  4.  
  5. public abstract class HttpURLConnection extends URLConnection {
  6.    protected String method = "GET";
  7.    protected int responseCode = -1;
  8.    protected String responseMessage;
  9.    private static boolean followRedirects = true;
  10.    private static final String[] methods = new String[]{"GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"};
  11.    public static final int HTTP_OK = 200;
  12.    public static final int HTTP_CREATED = 201;
  13.    public static final int HTTP_ACCEPTED = 202;
  14.    public static final int HTTP_NOT_AUTHORITATIVE = 203;
  15.    public static final int HTTP_NO_CONTENT = 204;
  16.    public static final int HTTP_RESET = 205;
  17.    public static final int HTTP_PARTIAL = 206;
  18.    public static final int HTTP_MULT_CHOICE = 300;
  19.    public static final int HTTP_MOVED_PERM = 301;
  20.    public static final int HTTP_MOVED_TEMP = 302;
  21.    public static final int HTTP_SEE_OTHER = 303;
  22.    public static final int HTTP_NOT_MODIFIED = 304;
  23.    public static final int HTTP_USE_PROXY = 305;
  24.    public static final int HTTP_BAD_REQUEST = 400;
  25.    public static final int HTTP_UNAUTHORIZED = 401;
  26.    public static final int HTTP_PAYMENT_REQUIRED = 402;
  27.    public static final int HTTP_FORBIDDEN = 403;
  28.    public static final int HTTP_NOT_FOUND = 404;
  29.    public static final int HTTP_BAD_METHOD = 405;
  30.    public static final int HTTP_NOT_ACCEPTABLE = 406;
  31.    public static final int HTTP_PROXY_AUTH = 407;
  32.    public static final int HTTP_CLIENT_TIMEOUT = 408;
  33.    public static final int HTTP_CONFLICT = 409;
  34.    public static final int HTTP_GONE = 410;
  35.    public static final int HTTP_LENGTH_REQUIRED = 411;
  36.    public static final int HTTP_PRECON_FAILED = 412;
  37.    public static final int HTTP_ENTITY_TOO_LARGE = 413;
  38.    public static final int HTTP_REQ_TOO_LONG = 414;
  39.    public static final int HTTP_UNSUPPORTED_TYPE = 415;
  40.    public static final int HTTP_SERVER_ERROR = 500;
  41.    public static final int HTTP_INTERNAL_ERROR = 501;
  42.    public static final int HTTP_BAD_GATEWAY = 502;
  43.    public static final int HTTP_UNAVAILABLE = 503;
  44.    public static final int HTTP_GATEWAY_TIMEOUT = 504;
  45.    public static final int HTTP_VERSION = 505;
  46.  
  47.    protected HttpURLConnection(URL var1) {
  48.       super(var1);
  49.    }
  50.  
  51.    public static void setFollowRedirects(boolean var0) {
  52.       SecurityManager var1 = System.getSecurityManager();
  53.       if (var1 != null) {
  54.          var1.checkSetFactory();
  55.       }
  56.  
  57.       followRedirects = var0;
  58.    }
  59.  
  60.    public static boolean getFollowRedirects() {
  61.       return followRedirects;
  62.    }
  63.  
  64.    public void setRequestMethod(String var1) throws ProtocolException {
  65.       if (super.connected) {
  66.          throw new ProtocolException("Can't reset method: already connected");
  67.       } else {
  68.          for(int var2 = 0; var2 < methods.length; ++var2) {
  69.             if (methods[var2].equals(var1)) {
  70.                this.method = var1;
  71.                return;
  72.             }
  73.          }
  74.  
  75.          throw new ProtocolException("Invalid HTTP method: " + var1);
  76.       }
  77.    }
  78.  
  79.    public String getRequestMethod() {
  80.       return this.method;
  81.    }
  82.  
  83.    public int getResponseCode() throws IOException {
  84.       if (this.responseCode != -1) {
  85.          return this.responseCode;
  86.       } else {
  87.          ((URLConnection)this).getInputStream();
  88.          String var1 = ((URLConnection)this).getHeaderField(0);
  89.  
  90.          try {
  91.             int var2;
  92.             for(var2 = var1.indexOf(32); var1.charAt(var2) == ' '; ++var2) {
  93.             }
  94.  
  95.             this.responseCode = Integer.parseInt(var1.substring(var2, var2 + 3));
  96.             this.responseMessage = var1.substring(var2 + 4).trim();
  97.             return this.responseCode;
  98.          } catch (Exception var3) {
  99.             return this.responseCode;
  100.          }
  101.       }
  102.    }
  103.  
  104.    public String getResponseMessage() throws IOException {
  105.       this.getResponseCode();
  106.       return this.responseMessage;
  107.    }
  108.  
  109.    public abstract void disconnect();
  110.  
  111.    public abstract boolean usingProxy();
  112. }
  113.