public class ClientHttpRequest
extends java.util.Observable
Title: MyJavaTools: Client HTTP Request class
Description: this class helps to send POST HTTP requests with various form data, including files. Cookies can be added to be included in the request.
Licensed under the myjavatools license (Apache license version 2.0) http://www.myjavatools.com/license.txtConstructor and Description |
---|
ClientHttpRequest(java.lang.String urlString)
Creates a new multipart POST HTTP request for a specified URL string
|
ClientHttpRequest(java.net.URL url)
Creates a new multipart POST HTTP request for a specified URL
|
ClientHttpRequest(java.net.URLConnection connection)
Creates a new multipart POST HTTP request on a freshly opened URLConnection
|
Modifier and Type | Method and Description |
---|---|
void |
cancel() |
protected void |
connect() |
int |
getBytesSent() |
long |
getFilePostSize(java.lang.String name,
java.io.File file) |
long |
getPostFooterSize() |
protected void |
newline() |
protected long |
newlineNumBytes() |
java.io.InputStream |
post()
Posts the requests to the server, with all the cookies and parameters that were added
|
java.io.InputStream |
post(java.util.Map parameters)
Posts the requests to the server, with all the cookies and parameters that were added before (if any), and with parameters that are passed in the argument
|
java.io.InputStream |
post(java.util.Map cookies,
java.util.Map parameters)
Posts the requests to the server, with all the cookies and parameters that were added before (if any), and with cookies and parameters that are passed in the arguments
|
java.io.InputStream |
post(java.lang.Object... parameters)
Posts the requests to the server, with all the cookies and parameters that were added before (if any), and with parameters that are passed in the argument
|
java.io.InputStream |
post(java.lang.String[] cookies,
java.lang.Object[] parameters)
Posts the requests to the server, with all the cookies and parameters that were added before (if any), and with cookies and parameters that are passed in the arguments
|
java.io.InputStream |
post(java.lang.String raw_cookies,
java.util.Map parameters)
Posts the requests to the server, with all the cookies and parameters that were added before (if any), and with cookies and parameters that are passed in the arguments
|
static java.io.InputStream |
post(java.net.URL url,
java.util.Map parameters)
Posts a new request to specified URL, with parameters that are passed in the argument
|
static java.io.InputStream |
post(java.net.URL url,
java.util.Map cookies,
java.util.Map parameters)
Posts a new request to specified URL, with cookies and parameters that are passed in the argument
|
static java.io.InputStream |
post(java.net.URL url,
java.lang.Object[] parameters)
Posts a new request to specified URL, with parameters that are passed in the argument
|
static java.io.InputStream |
post(java.net.URL url,
java.lang.String[] cookies,
java.lang.Object[] parameters)
Posts a new request to specified URL, with cookies and parameters that are passed in the argument
|
protected static java.lang.String |
randomString() |
void |
setCookie(java.lang.String name,
java.lang.String value)
Adds a cookie to the requst
|
void |
setCookies(java.util.Map cookies)
Adds cookies to the request
|
void |
setCookies(java.lang.String rawCookies)
Adds a cookie to the requst
|
void |
setCookies(java.lang.String[] cookies)
Adds cookies to the request
|
void |
setParameter(java.lang.Object name,
java.lang.Object object)
Adds a parameter to the request; if the parameter is a File, the file is uploaded, otherwise the string value of the parameter is passed in the request
|
void |
setParameter(java.lang.String name,
java.io.File file)
Adds a file parameter to the request
|
void |
setParameter(java.lang.String name,
java.lang.String value)
Adds a string parameter to the request
|
void |
setParameter(java.lang.String name,
java.lang.String filename,
java.io.InputStream is)
Adds a file parameter to the request
|
void |
setParameters(java.util.Map parameters)
Adds parameters to the request
|
void |
setParameters(java.lang.Object... parameters)
Adds parameters to the request
|
protected void |
write(char c) |
protected void |
write(java.lang.String s) |
protected void |
writeln(java.lang.String s) |
public ClientHttpRequest(java.net.URLConnection connection) throws java.io.IOException
connection
- an already open URL connectionjava.io.IOException
public ClientHttpRequest(java.net.URL url) throws java.io.IOException
url
- the URL to send request tojava.io.IOException
public ClientHttpRequest(java.lang.String urlString) throws java.io.IOException
urlString
- the string representation of the URL to send request tojava.io.IOException
protected void connect() throws java.io.IOException
java.io.IOException
protected void write(char c) throws java.io.IOException
java.io.IOException
protected void write(java.lang.String s) throws java.io.IOException
java.io.IOException
protected long newlineNumBytes()
protected void newline() throws java.io.IOException
java.io.IOException
protected void writeln(java.lang.String s) throws java.io.IOException
java.io.IOException
protected static java.lang.String randomString()
public void setCookies(java.lang.String rawCookies) throws java.io.IOException
name
- cookie namevalue
- cookie valuejava.io.IOException
public void setCookie(java.lang.String name, java.lang.String value) throws java.io.IOException
name
- cookie namevalue
- cookie valuejava.io.IOException
public void setCookies(java.util.Map cookies) throws java.io.IOException
cookies
- the cookie "name-to-value" mapjava.io.IOException
public void setCookies(java.lang.String[] cookies) throws java.io.IOException
cookies
- array of cookie names and values
(cookies[2*i] is a name, cookies[2*i + 1] is a value)java.io.IOException
public int getBytesSent()
public void cancel()
public void setParameter(java.lang.String name, java.lang.String value) throws java.io.IOException
name
- parameter namevalue
- parameter valuejava.io.IOException
public void setParameter(java.lang.String name, java.lang.String filename, java.io.InputStream is) throws java.io.IOException
name
- parameter namefilename
- the name of the fileis
- input stream to read the contents of the file fromjava.io.IOException
public long getFilePostSize(java.lang.String name, java.io.File file)
public void setParameter(java.lang.String name, java.io.File file) throws java.io.IOException
name
- parameter namefile
- the file to uploadjava.io.IOException
public void setParameter(java.lang.Object name, java.lang.Object object) throws java.io.IOException
name
- parameter nameobject
- parameter value, a File or anything else that can be stringifiedjava.io.IOException
public void setParameters(java.util.Map parameters) throws java.io.IOException
parameters
- "name-to-value" map of parameters; if a value is a file, the file is uploaded, otherwise it is stringified and sent in the requestjava.io.IOException
public void setParameters(java.lang.Object... parameters) throws java.io.IOException
parameters
- (vararg) parameter names and values (parameters[2*i] is a name, parameters[2*i + 1] is a value); if a value is a file, the file is uploaded, otherwise it is stringified and sent in the requestjava.io.IOException
public long getPostFooterSize()
public java.io.InputStream post() throws java.io.IOException
java.io.IOException
public java.io.InputStream post(java.util.Map parameters) throws java.io.IOException
parameters
- request parametersjava.io.IOException
setParameters
public java.io.InputStream post(java.lang.Object... parameters) throws java.io.IOException
parameters
- request parametersjava.io.IOException
setParameters
public java.io.InputStream post(java.util.Map cookies, java.util.Map parameters) throws java.io.IOException
cookies
- request cookiesparameters
- request parametersjava.io.IOException
setParameters
,
setCookies
public java.io.InputStream post(java.lang.String raw_cookies, java.util.Map parameters) throws java.io.IOException
cookies
- request cookiesparameters
- request parametersjava.io.IOException
setParameters
,
setCookies
public java.io.InputStream post(java.lang.String[] cookies, java.lang.Object[] parameters) throws java.io.IOException
cookies
- request cookiesparameters
- request parametersjava.io.IOException
setParameters
,
setCookies
public static java.io.InputStream post(java.net.URL url, java.util.Map parameters) throws java.io.IOException
parameters
- request parametersjava.io.IOException
setParameters
public static java.io.InputStream post(java.net.URL url, java.lang.Object[] parameters) throws java.io.IOException
parameters
- request parametersjava.io.IOException
setParameters
public static java.io.InputStream post(java.net.URL url, java.util.Map cookies, java.util.Map parameters) throws java.io.IOException
cookies
- request cookiesparameters
- request parametersjava.io.IOException
setCookies
,
setParameters
public static java.io.InputStream post(java.net.URL url, java.lang.String[] cookies, java.lang.Object[] parameters) throws java.io.IOException
cookies
- request cookiesparameters
- request parametersjava.io.IOException
setCookies
,
setParameters