Interface HttpRequest

All Known Implementing Classes:
SimpleHttpRequest

public interface HttpRequest
The HttpRequest interface should be implemented to provide web request capabilities. It is used a similar manner to XMLHttpRequest in Javascript (AJAX). Normally, a listener will be added by calling addReadyStateChangeListener(ReadyStateChangeListener), the method open will be called, and finally, send(String) will be called to complete the request.
See Also:
  • Field Details

    • STATE_UNINITIALIZED

      static final int STATE_UNINITIALIZED
      The uninitialized request state.
      See Also:
    • STATE_LOADING

      static final int STATE_LOADING
      The loading request state. The open method has been called, but a response has not been received yet.
      See Also:
    • STATE_LOADED

      static final int STATE_LOADED
      The loaded request state. Headers and status are now available.
      See Also:
    • STATE_INTERACTIVE

      static final int STATE_INTERACTIVE
      The interactive request state. Downloading response.
      See Also:
    • STATE_COMPLETE

      static final int STATE_COMPLETE
      The complete request state. All operations are finished.
      See Also:
  • Method Details

    • getReadyState

      int getReadyState()
      Gets the state of the request, a value between 0 and 4.
      Returns:
      A value corresponding to one of the STATE* constants in this class.
    • getResponseText

      String getResponseText()
      Gets the request response as text.
    • getResponseXML

      Document getResponseXML()
      Gets the request response as an XML DOM.
    • getResponseImage

      Image getResponseImage()
      Gets the request response as an AWT image.
    • getResponseBytes

      byte[] getResponseBytes()
      Gets the request response bytes.
    • getStatus

      int getStatus()
      Gets the status of the response. Note that this can be 0 for file requests in addition to 200 for successful HTTP requests.
    • getStatusText

      String getStatusText()
      Gets the status text of the request, e.g. "OK" for 200.
    • abort

      void abort()
      Aborts an ongoing request.
    • getAllResponseHeaders

      String getAllResponseHeaders()
      Gets a string with all the response headers.
    • getResponseHeader

      String getResponseHeader(String headerName)
      Gets a response header value.
      Parameters:
      headerName - The name of the header.
    • open

      void open(String method, String url) throws IOException
      Starts an asynchronous request.
      Parameters:
      method - The request method.
      url - The destination URL.
      Throws:
      IOException
    • open

      void open(String method, URL url) throws IOException
      Opens an asynchronous request.
      Parameters:
      method - The request method.
      url - The destination URL.
      Throws:
      IOException
    • open

      void open(String method, URL url, boolean asyncFlag) throws IOException
      Opens an request.
      Parameters:
      method - The request method.
      url - The destination URL.
      asyncFlag - Whether the request is asynchronous.
      Throws:
      IOException
    • open

      void open(String method, String url, boolean asyncFlag) throws IOException
      Opens a request.
      Parameters:
      method - The request method.
      url - The destination URL.
      asyncFlag - Whether the request should be asynchronous.
      Throws:
      IOException
    • open

      void open(String method, URL url, boolean asyncFlag, String userName) throws IOException
      Opens a request.
      Parameters:
      method - The request method.
      url - The destination URL.
      asyncFlag - Whether the request should be asynchronous.
      userName - The HTTP authentication user name.
      Throws:
      IOException
    • open

      void open(String method, URL url, boolean asyncFlag, String userName, String password) throws IOException
      Opens a request.
      Parameters:
      method - The request method.
      url - The destination URL.
      asyncFlag - Whether the request should be asynchronous.
      userName - The HTTP authentication user name.
      password - The HTTP authentication password.
      Throws:
      IOException
    • send

      void send(String content) throws IOException
      Sends POST content if any.
      Parameters:
      content - POST content or null for GET requests.
      Throws:
      IOException
    • addReadyStateChangeListener

      void addReadyStateChangeListener(ReadyStateChangeListener listener)
      Adds a listener of ReadyState changes. The listener should be invoked even in the case of errors.
      Parameters:
      listener - An instanceof of ReadyStateChangeListener