abstract class Http
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) static boolean |
DEBUGGING
true if want extra debugging output.
|
(package private) static int |
DEFAULT_LENGTH
message length to presume when no length given
|
(package private) static int |
DEFAULT_RESPONSE_CODE
responseCode to give if is no proper one
|
(package private) static java.lang.String |
DEFAULT_RESPONSE_MESSAGE
responseMessage to give if is no proper one.
|
static java.lang.String |
EMBEDDED_COPYRIGHT
undisplayed copyright notice
|
(package private) int |
readTimeout
Allow 40 seconds for a read to go without progress, measured in millis.
|
(package private) int |
responseCode
responseCode from most recent post
|
(package private) java.lang.String |
responseMessage
responseCode in words from most recent post
|
(package private) java.net.URL |
url
URL, including encoded get Parameters.
|
static java.nio.charset.Charset |
UTF8Charset
encoding for UTF-8
|
static java.lang.String |
VERSION_STRING
embedded version string.
|
Constructor and Description |
---|
Http()
no public instantiation.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
dumpHeaders(java.lang.String title,
java.net.HttpURLConnection urlc)
display the contents of the header fields key: value, value, value
|
(package private) java.lang.String |
getEncodedParms(java.nio.charset.Charset encoding)
get the parms for the command encoded, separated with ? = & = *
|
java.lang.String |
getRawResponseMessage()
responseCode from most recent post/get exactly as received from the server
|
java.lang.String |
getReferer()
ges the Referrer ie.
|
int |
getResponseCode()
responseCode from most recent post/get
Meaning of various codes are described at HttpURLConnection and at http://mindprod.com/jgloss/http.html
|
java.lang.String |
getResponseMessage()
responseCode from most recent post/get tidied to standard form
|
java.net.URL |
getURL()
Get URL for this connection.
|
(package private) static java.nio.charset.Charset |
guessCharSet(java.lang.String contentType,
java.nio.charset.Charset defaultEncoding)
Guess what charSet encoding the response will be in.
|
(package private) java.lang.String |
processResponse(java.nio.charset.Charset defaultCharSet,
java.net.HttpURLConnection urlc)
process the response from the request we sent the server
|
void |
setConnectTimeout(int connectTimeout)
override the default connect timeout of 50 seconds
|
void |
setInstanceFollowRedirects(boolean followRedirects)
control whether redirects are automatically followed or treated as errors.
|
void |
setParms(java.lang.String... parms)
set the parms that will be send tacked onto the end of the URL, get-style
|
void |
setReadTimeout(int readTimeout)
override the default read timeout of 40 seconds
|
void |
setReferer(java.lang.String referer)
set the Referrer ie.
|
void |
setRequestProperties(java.lang.String... requestProperties)
set additional requestProperties.
|
protected void |
setStandardProperties(java.net.URLConnection urlc)
set up the standard properties on the connection
|
void |
setUserAgent(java.lang.String userAgent)
override the default User-Agent
|
static final boolean DEBUGGING
static final int DEFAULT_LENGTH
static final int DEFAULT_RESPONSE_CODE
static final java.lang.String DEFAULT_RESPONSE_MESSAGE
public static final java.lang.String EMBEDDED_COPYRIGHT
public static final java.lang.String VERSION_STRING
public static final java.nio.charset.Charset UTF8Charset
java.lang.String responseMessage
java.net.URL url
int readTimeout
int responseCode
public java.lang.String getRawResponseMessage()
getResponseMessage()
public java.lang.String getReferer()
public void setReferer(java.lang.String referer)
referer
- e.g "http://mindprod.com/index.html", null for none.public int getResponseCode()
HttpURLConnection
public java.lang.String getResponseMessage()
public java.net.URL getURL()
public void setConnectTimeout(int connectTimeout)
connectTimeout
- timeout to connect in ms. Note int, not long.public void setInstanceFollowRedirects(boolean followRedirects)
followRedirects
- true=auto follow, false=treat as error..HttpURLConnection.setInstanceFollowRedirects(boolean)
public void setParms(java.lang.String... parms)
parms
- 0..n strings to be send as parameter, alternating keyword/valuePost.setPostParms(String...)
public void setReadTimeout(int readTimeout)
readTimeout
- timeout to connect int ms. Note int, not long.public void setRequestProperties(java.lang.String... requestProperties)
requestProperties
- pairs: key value.public void setUserAgent(java.lang.String userAgent)
userAgent
- User-Agent a browser uses in an HTTP header to identify itself.
null for no User Agent. By default you get Firefox.protected static void dumpHeaders(java.lang.String title, java.net.HttpURLConnection urlc)
title
- Title to decorated the dump.urlc
- HTTP connectionstatic java.nio.charset.Charset guessCharSet(java.lang.String contentType, java.nio.charset.Charset defaultEncoding)
contentType
- contents of content type fielddefaultEncoding
- charSet to use if empty content type field, e.g. "UTF-8"java.lang.String getEncodedParms(java.nio.charset.Charset encoding) throws java.io.UnsupportedEncodingException
encoding
- for URLEncoderjava.io.UnsupportedEncodingException
- if bad encodingjava.lang.String processResponse(java.nio.charset.Charset defaultCharSet, java.net.HttpURLConnection urlc) throws java.io.IOException
defaultCharSet
- Encoding to use to interpret the result.urlc
- the HttpURLConnection, all ready to go but for the connect.java.io.IOException
- if trouble reading the stream.protected void setStandardProperties(java.net.URLConnection urlc)
urlc
- Connection we are setting up.