public class HttpUtil
extends java.lang.Object
HttpUtil
class contains methods for performing simple
HTTP operations.Modifier and Type | Method and Description |
---|---|
static void |
extractQuery(java.lang.String query,
java.util.Dictionary table)
Turns x-www-form-urlencoded form data into a dictionary.
|
static java.lang.String |
extractUrlHost(java.lang.String url)
Get the host portion of a Url String.
|
static java.lang.String |
extractUrlPath(java.lang.String url)
Get the path portion of a Url String.
|
static java.lang.String |
extractUrlPort(java.lang.String url)
Get the port portion of a Url String as a string.
|
static java.lang.String |
extractUrlProtocol(java.lang.String url)
Get the protocol portion of a Url String.
|
static java.lang.String |
formatTime()
Returns a string containing the current time as an HTTP-formatted
date.
|
static java.lang.String |
formatTime(long time)
Returns a string containing an HTTP-formatted date.
|
static java.lang.String |
getStatusPhrase(int code)
Returns the HTTP error string associated with the integer error code.
|
static java.lang.String |
htmlEncode(java.lang.String src)
Converts a string into a valid HTML fragment.
|
static long |
parseTime(java.lang.String time)
Convert a last-modified date in "standard" format
into a time stamp.
|
static java.lang.String |
urlDecode(java.lang.String src)
Decodes a URL-encoded string by replacing all the "%XX" escape
sequences in the string with the corresponding character.
|
static java.lang.String |
urlEncode(java.lang.String src)
Maps a string to be used in a query or post into a form that is
acceptable in an URL.
|
public static java.lang.String htmlEncode(java.lang.String src)
&#xx;
(their "decimal
reference" form).src
- The string to convert.public static java.lang.String urlEncode(java.lang.String src)
URL strings may not contain non-alphanumeric characters. All non-alphanumeric characters are converted to the escape sequence "%XX", where XX is the hexadecimal value of that character's code.
Note that the space character " " is NOT converted to "+". That is a common misconception. "+" represents a space only in query strings, not in the URL. "%20" is how an actual space character must be passed in an URL, and is also an acceptable way of passing a space in a query string.
string
- The string to convert.public static java.lang.String urlDecode(java.lang.String src)
Malformed "%XX" sequences are silently ignored.
string
- The URL-encoded string.public static java.lang.String formatTime()
public static java.lang.String formatTime(long time)
time
- The date to format (current time in msec).public static long parseTime(java.lang.String time)
time
- A correctly formatted HTTP date string.public static void extractQuery(java.lang.String query, java.util.Dictionary table)
query
- The x-www-form-urlencoded string. May be null
table
- The dictionary to insert the form data into.public static java.lang.String extractUrlProtocol(java.lang.String url)
public static java.lang.String extractUrlHost(java.lang.String url)
public static java.lang.String extractUrlPort(java.lang.String url)
public static java.lang.String extractUrlPath(java.lang.String url)
public static java.lang.String getStatusPhrase(int code)
code
- The code to look up.