All Packages Class Hierarchy This Package Previous Next Index
Class com.andthehorseyourodeinon.utils.HTTPUtils
java.lang.Object
|
+----com.andthehorseyourodeinon.utils.HTTPUtils
- public class HTTPUtils
- extends Object
HTTPUtils is a statically-called utility class that contains useful functions
for HTTP-related activity. Some of these are pretty badly written, and are
only included for legacy reasons. Caveat Emptor!
- Version:
- $Id: HTTPUtils.java,v 1.1 2000/05/16 22:45:10 samuelg Exp $
-
CRLFLEN
-
-
HTTPUtils()
-
-
acceptingConnections(InetAddress, int)
- This function uses up a fair amount of network traffic to determine whether
or not a given host is willing to serve up a general document via HTTP.
-
acceptingConnections(InetAddress, int, String)
- This function uses up a fair amount of network traffic to determine whether
or not a given host is willing to serve up a given document.
-
acceptingConnections(URL)
- This function uses up a fair amount of network traffic to determine whether
or not a given host is willing to serve up a given document.
-
copyStream(InputStream, OutputStream)
- A routine to copy an InputStream to and OutputStream.
-
downloadHTMLPageRaw(String, Vector, String, String)
- A primitive, socket-based approach to an HTTP GET, which then dumps to a file.
-
formSubmission(BufferedReader)
- This allows the processing of a HTML Form (or the equivalent) as submitted
by a typical web browser.
-
getHTMLPage(String, Hashtable)
- Given a URL and an optional collection of cookies, this will build a connection
to that URL and prepare an InputStream to enable reading of the results.
-
getHTMLPageRaw(String, Vector, int)
- A primitive, socket-based approach to an HTTP GET.
-
getHTMLStream(String, Hashtable)
- Given a URL and an optional collection of cookies, this will build a connection
to that URL and prepare an InputStream to enable reading of the results.
-
getHTMLStreamRaw(String, Vector)
- A primitive, socket-based approach to an HTTP GET.
-
getHTMLStreamRaw(String, Vector, String)
- A primitive, socket-based approach to an HTTP GET.
-
httpPost(String, String)
- Given a URL and encoded data, this will build a connection
to that URL and perform an HTTP POST of that data.
-
httpPostRaw(String, String, String)
- A primitive, socket-based approach to an HTTP POST.
-
multiPartForm(PostedForm, BufferedReader)
-
Handles a multi-part Form submission.
-
singlePartForm(PostedForm, BufferedReader)
-
Handles a single-part Form submission.
-
statusMessage(int)
- converts an HTTP status code into its corresponding text message e.g.,
statusMessage(200) returns "OK", or statusMessage(404) returns "Not Found".
-
URLDecoder(String)
- The antithesis to URLEncoder.encode().
CRLFLEN
public static final int CRLFLEN
HTTPUtils
public HTTPUtils()
statusMessage
public static String statusMessage(int statusCode)
- converts an HTTP status code into its corresponding text message e.g.,
statusMessage(200) returns "OK", or statusMessage(404) returns "Not Found".
These should be RFC 2068 and RFC 2616 compliant.
- Parameters:
- statusCode - an integer HTTP status code
- Returns:
- String containing status message
acceptingConnections
public static boolean acceptingConnections(InetAddress theAddress,
int thePort)
- This function uses up a fair amount of network traffic to determine whether
or not a given host is willing to serve up a general document via HTTP.
- Parameters:
- theAddress - the InetAddress of the server to test.
- thePort - the port to talk to (for Web servers, this will generally be port 80).
- Returns:
- true if the host will serve that document to this client.
acceptingConnections
public static boolean acceptingConnections(InetAddress theAddress,
int thePort,
String theRequest)
- This function uses up a fair amount of network traffic to determine whether
or not a given host is willing to serve up a given document.
- Parameters:
- theAddress - the InetAddress of the server to test.
- thePort - the port to talk to (for Web servers, this will generally be port 80)
- theRequest - the relative path and name of the document to test for on the specified host.
- Returns:
- true if the host will serve that document to this client.
acceptingConnections
public static boolean acceptingConnections(URL theUrl)
- This function uses up a fair amount of network traffic to determine whether
or not a given host is willing to serve up a given document.
- Parameters:
- theUrl - the URL of the document to test for.
- Returns:
- true if the host will serve that document to this client.
formSubmission
public static PostedForm formSubmission(BufferedReader br)
- This allows the processing of a HTML Form (or the equivalent) as submitted
by a typical web browser. It is still somewhat rudimentary, although it has been
successfully tested using Netscape 4.7 and Internet Explorer 4 and 5.
It can be used for standard HTML forms, as well as file upload or other multipart
forms.
It identifies which kind of form has been submitted, and calls dispatches the request
to either the singlePartForm or multiPartForm method.
- Parameters:
- br - A BufferedReader that contains the HTML Form submission.
- Returns:
- a PostedForm structure of the form contents.
- See Also:
- PostedForm
multiPartForm
public static void multiPartForm(PostedForm p,
BufferedReader br)
- Handles a multi-part Form submission. Contents are placed into the PostedForm.
Yuck!
All this conversion back and forth hurts!
There's gotta be a better way...
- Parameters:
- p - a PostedForm to use as a data store.
- br - the BufferedReader through which the submission is received.
singlePartForm
public static void singlePartForm(PostedForm p,
BufferedReader br)
- Handles a single-part Form submission. Contents are placed into the PostedForm.
- Parameters:
- p - a PostedForm to use as a data store.
- br - the BufferedReader through which the submission is received.
URLDecoder
public static String URLDecoder(String content)
- The antithesis to URLEncoder.encode().
This may be a bit weak, but it seems to work on simple application/x-www-url-encoded strings.
- Parameters:
- content - the String to decode
- Returns:
- the decoded String
getHTMLStream
public static InputStream getHTMLStream(String urlString,
Hashtable cookies)
- Given a URL and an optional collection of cookies, this will build a connection
to that URL and prepare an InputStream to enable reading of the results. There is some general
lameness here -- the routine doesn't allow you to specify your own headers, nor pass more than
one cookie.
- Parameters:
- urlString - the URL to connect to.
- cookies - a Hashtable containing any cookie information that you want to pass to
the server, as a collection of name-value pairs.
- Returns:
- an InputStream from which you can read the response of the URL.
getHTMLPage
public static String getHTMLPage(String urlString,
Hashtable cookies)
- Given a URL and an optional collection of cookies, this will build a connection
to that URL and prepare an InputStream to enable reading of the results. There is some general
lameness here -- the routine doesn't allow you to specify your own headers, nor pass more than
one cookie.
- Parameters:
- urlString - the URL to connect to.
- cookies - a Hashtable containing any cookie information that you want to pass to
the server, as a collection of name-value pairs.
- Returns:
- a String containing the response of the URL.
getHTMLPageRaw
public static String getHTMLPageRaw(String urlString,
Vector cookieList,
int depth)
- A primitive, socket-based approach to an HTTP GET.
There is a great deal of
uncruftiness here -- the routine doesn't allow you to specify your own headers, and is generally
pretty narrowly implemented. Because it tries to follow redirects, this routine will recurse. The
cut-off of five redirects is pretty arbitrary.
- Parameters:
- urlString - the URL to connect to.
- cookies - a Vector containing prepared Cookie header fields.
- depth - number of times we've recursed. You'll generally want to call it with 0.
- Returns:
- a String containing the response of the URL.
getHTMLStreamRaw
public static InputStream getHTMLStreamRaw(String urlString,
Vector cookieList)
- A primitive, socket-based approach to an HTTP GET.
There is a great deal of
uncruftiness here -- the routine doesn't allow you to specify your own headers, and is generally
pretty narrowly implemented.
- Parameters:
- urlString - the URL to connect to.
- cookies - a Vector containing prepared Cookie header fields.
- Returns:
- an InputStream from which you can read the response of the URL.
getHTMLStreamRaw
public static InputStream getHTMLStreamRaw(String urlString,
Vector cookieList,
String proxy)
- A primitive, socket-based approach to an HTTP GET.
There is a great deal of
uncruftiness here -- the routine doesn't allow you to specify your own headers, and is generally
pretty narrowly implemented. This also has a proxy parameter that will allow communication via an
HTTP proxy.
- Parameters:
- urlString - the URL to connect to.
- cookies - a Vector containing prepared Cookie header fields.
- proxy - a HTTP proxy address
- Returns:
- an InputStream from which you can read the response of the URL.
downloadHTMLPageRaw
public static boolean downloadHTMLPageRaw(String urlString,
Vector cookies,
String fileName,
String proxy)
- A primitive, socket-based approach to an HTTP GET, which then dumps to a file.
There is a great deal of
uncruftiness here -- the routine doesn't allow you to specify your own headers, and is generally
pretty narrowly implemented. It also has a proxy parameter that will allow communication via an
HTTP proxy.
- Parameters:
- urlString - the URL to connect to.
- cookies - a Vector containing prepared Cookie header fields.
- fileName - the file to dump the response into
- proxy - a HTTP proxy address
- Returns:
- a boolean indicating success or failure.
copyStream
public static void copyStream(InputStream in,
OutputStream out) throws IOException
- A routine to copy an InputStream to and OutputStream.
- Parameters:
- in - the source InputStream
- out - the destination OutputStream
httpPost
public static String httpPost(String urlString,
String urlEncodedData)
- Given a URL and encoded data, this will build a connection
to that URL and perform an HTTP POST of that data. There is some general
lameness here -- the routine doesn't allow you to specify your own headers.
- Parameters:
- urlString - the URL to connect to.
- urlEncodedData - whatever it is that you want to pass to
the server, as a collection of name-value pairs.
- Returns:
- a String containing the response from the server.
httpPostRaw
public static String httpPostRaw(String urlString,
String urlEncodedData,
String cookie)
- A primitive, socket-based approach to an HTTP POST.
This is indeed
uncrufty -- the routine doesn't allow you to specify your own headers, allows only a single cookie,
and is generally pretty narrowly implemented.
- Parameters:
- urlString - the URL to connect to.
- urlEncodedData - whatever it is that you want to pass to
the server, as a collection of name-value pairs.
- cookie - you can pass a single cookie along as a String
- Returns:
- a String containing the response from the server.
All Packages Class Hierarchy This Package Previous Next Index