|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindprod.http.Post
public final class Post
simulates a browser posting a form to CGI via POST.
See com.mindprod.submitter for sample code to use this class.
Field Summary | |
---|---|
static java.lang.String |
EMBEDDED_COPYRIGHT
undisplayed copyright notice |
static java.lang.String |
VERSION_STRING
embedded version string. |
Constructor Summary | |
---|---|
Post()
Constructor |
Method Summary | |
---|---|
protected static void |
dumpHeaders(java.lang.String title,
java.net.HttpURLConnection urlc)
display the contents of the header fields key: value, value, value |
static java.lang.String |
encodeParms(java.lang.String encoding,
java.lang.String... parms)
encode a set of parms for the command, separated with ? = & = * This method does not automatically include the result in the message sent to the host. |
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 |
java.net.URL |
getURL()
Get URL for this connection. |
java.lang.String |
send(java.lang.String host,
int port,
java.lang.String action,
java.lang.String encoding)
Send a form full of data to the CGI host using POST setPostParms must have been called previously, and possibly setParms as well. |
java.lang.String |
send(java.net.URL url,
java.lang.String encoding)
Send a form full of data to the CGI host using POST Must have done a setParms(optional) and setPostParms beforehand. |
void |
setConnectTimeout(int connectTimeout)
override the default connect timeout of 50 seconds |
void |
setContentType(java.lang.String contentType)
declare Mime Type of the message contents. |
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 |
setPostBody(java.lang.String body)
set the body of the post, after the post parms. |
void |
setPostParms(java.lang.String... postParms)
set the parms that will be send in the Post body. |
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String EMBEDDED_COPYRIGHT
public static final java.lang.String VERSION_STRING
Constructor Detail |
---|
public Post()
Method Detail |
---|
public java.lang.String send(java.net.URL url, java.lang.String encoding)
url
- URL of the website, including host, path but not the parms.
Call setPostParms and setPostBody before calling send.
http: or https:encoding
- encoding of the byte stream result, usually UTF-8 or or ISO-8859-1.
public java.lang.String send(java.lang.String host, int port, java.lang.String action, java.lang.String encoding)
host
- domain of the website. no lead http:port
- -1 if default, 8081 for local echoserver.action
- action of form, page on website. Usually has a lead /.encoding
- encoding of the byte stream result, usually UTF-8 or or ISO-8859-1.
public void setContentType(java.lang.String contentType)
contentType
- mime type of messagepublic void setPostBody(java.lang.String body)
body
- text to form the body of the post.setPostParms(String...)
public void setPostParms(java.lang.String... postParms)
postParms
- 0..n strings to be send as parameter, alternating keyword/valueHttp.setParms(String...)
public static java.lang.String encodeParms(java.lang.String encoding, java.lang.String... parms) throws java.io.UnsupportedEncodingException
encoding
- for URLEncoderparms
- 0..n strings to be send as parameter, alternating keyword/value
java.io.UnsupportedEncodingException
- if bad encodingpublic 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/valuesetPostParms(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 connectionprotected void setStandardProperties(java.net.URLConnection urlc)
urlc
- Connection we are setting up.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |