
public class ClientHttpRequest extends Object
Title: 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.
| Constructor and Description |
|---|
ClientHttpRequest(String urlString)
Creates a new multipart POST HTTP request for a specified URL string
|
ClientHttpRequest(URL url)
Creates a new multipart POST HTTP request for a specified URL
|
ClientHttpRequest(URLConnection connection)
Creates a new multipart POST HTTP request on a freshly opened
URLConnection
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
connect() |
protected void |
newline() |
InputStream |
post()
posts the requests to the server, with all the cookies and parameters
that were added
|
InputStream |
post(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
|
InputStream |
post(Map cookies,
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
|
InputStream |
post(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
|
InputStream |
post(String[] cookies,
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
|
InputStream |
post(String name,
Object value)
post the POST request to the server, with the specified parameter
|
InputStream |
post(String name1,
Object value1,
String name2,
Object value2)
post the POST request to the server, with the specified parameters
|
InputStream |
post(String name1,
Object value1,
String name2,
Object value2,
String name3,
Object value3)
post the POST request to the server, with the specified parameters
|
InputStream |
post(String name1,
Object value1,
String name2,
Object value2,
String name3,
Object value3,
String name4,
Object value4)
post the POST request to the server, with the specified parameters
|
static InputStream |
post(URL url,
Map parameters)
posts a new request to specified URL, with parameters that are passed in
the argument
|
static InputStream |
post(URL url,
Map cookies,
Map parameters)
posts a new request to specified URL, with cookies and parameters that
are passed in the argument
|
static InputStream |
post(URL url,
Object[] parameters)
posts a new request to specified URL, with parameters that are passed in
the argument
|
static InputStream |
post(URL url,
String[] cookies,
Object[] parameters)
posts a new request to specified URL, with cookies and parameters that
are passed in the argument
|
static InputStream |
post(URL url,
String name1,
Object value1)
post the POST request specified URL, with the specified parameter
|
static InputStream |
post(URL url,
String name1,
Object value1,
String name2,
Object value2)
post the POST request to specified URL, with the specified parameters
|
static InputStream |
post(URL url,
String name1,
Object value1,
String name2,
Object value2,
String name3,
Object value3)
post the POST request to specified URL, with the specified parameters
|
static InputStream |
post(URL url,
String name1,
Object value1,
String name2,
Object value2,
String name3,
Object value3,
String name4,
Object value4)
post the POST request to specified URL, with the specified parameters
|
protected static String |
randomString() |
void |
setCookie(String name,
String value)
adds a cookie to the requst
|
void |
setCookies(Map cookies)
adds cookies to the request
|
void |
setCookies(String[] cookies)
adds cookies to the request
|
void |
setParameter(String name,
File file)
adds a file parameter to the request
|
void |
setParameter(String name,
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(String name,
String value)
adds a string parameter to the request
|
void |
setParameter(String name,
String filename,
InputStream is)
adds a file parameter to the request
|
void |
setParameters(Map parameters)
adds parameters to the request
|
void |
setParameters(Object[] parameters)
adds parameters to the request
|
protected void |
write(char c) |
protected void |
write(String s) |
protected void |
writeln(String s) |
public ClientHttpRequest(URLConnection connection) throws IOException
connection - an already open URL connectionIOExceptionpublic ClientHttpRequest(URL url) throws IOException
url - the URL to send request toIOExceptionpublic ClientHttpRequest(String urlString) throws IOException
urlString - the string representation of the URL to send request toIOExceptionprotected void connect()
throws IOException
IOExceptionprotected void write(char c)
throws IOException
IOExceptionprotected void write(String s) throws IOException
IOExceptionprotected void newline()
throws IOException
IOExceptionprotected void writeln(String s) throws IOException
IOExceptionprotected static String randomString()
public void setCookie(String name, String value) throws IOException
name - cookie namevalue - cookie valueIOExceptionpublic void setCookies(Map cookies) throws IOException
cookies - the cookie "name-to-value" mapIOExceptionpublic void setCookies(String[] cookies) throws IOException
cookies - array of cookie names and values (cookies[2*i] is a name,
cookies[2*i + 1] is a value)IOExceptionpublic void setParameter(String name, String value) throws IOException
name - parameter namevalue - parameter valueIOExceptionpublic void setParameter(String name, String filename, InputStream is) throws IOException
name - parameter namefilename - the name of the fileis - input stream to read the contents of the file fromIOExceptionpublic void setParameter(String name, File file) throws IOException
name - parameter namefile - the file to uploadIOExceptionpublic void setParameter(String name, Object object) throws IOException
name - parameter nameobject - parameter value, a File or anything else that can be
stringifiedIOExceptionpublic void setParameters(Map parameters) throws 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
requestIOExceptionpublic void setParameters(Object[] parameters) throws IOException
parameters - array of 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 requestIOExceptionpublic InputStream post() throws IOException
IOExceptionpublic InputStream post(Map parameters) throws IOException
parameters - request parametersIOExceptionsetParameterspublic InputStream post(Object[] parameters) throws IOException
parameters - request parametersIOExceptionsetParameterspublic InputStream post(Map cookies, Map parameters) throws IOException
cookies - request cookiesparameters - request parametersIOExceptionsetParameters,
setCookiespublic InputStream post(String[] cookies, Object[] parameters) throws IOException
cookies - request cookiesparameters - request parametersIOExceptionsetParameters,
setCookiespublic InputStream post(String name, Object value) throws IOException
name - parameter namevalue - parameter valueIOExceptionsetParameterpublic InputStream post(String name1, Object value1, String name2, Object value2) throws IOException
name1 - first parameter namevalue1 - first parameter valuename2 - second parameter namevalue2 - second parameter valueIOExceptionsetParameterpublic InputStream post(String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException
name1 - first parameter namevalue1 - first parameter valuename2 - second parameter namevalue2 - second parameter valuename3 - third parameter namevalue3 - third parameter valueIOExceptionsetParameterpublic InputStream post(String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException
name1 - first parameter namevalue1 - first parameter valuename2 - second parameter namevalue2 - second parameter valuename3 - third parameter namevalue3 - third parameter valuename4 - fourth parameter namevalue4 - fourth parameter valueIOExceptionsetParameterpublic static InputStream post(URL url, Map parameters) throws IOException
parameters - request parametersIOExceptionsetParameterspublic static InputStream post(URL url, Object[] parameters) throws IOException
parameters - request parametersIOExceptionsetParameterspublic static InputStream post(URL url, Map cookies, Map parameters) throws IOException
cookies - request cookiesparameters - request parametersIOExceptionsetCookies,
setParameterspublic static InputStream post(URL url, String[] cookies, Object[] parameters) throws IOException
cookies - request cookiesparameters - request parametersIOExceptionsetCookies,
setParameterspublic static InputStream post(URL url, String name1, Object value1) throws IOException
name - parameter namevalue - parameter valueIOExceptionsetParameterpublic static InputStream post(URL url, String name1, Object value1, String name2, Object value2) throws IOException
name1 - first parameter namevalue1 - first parameter valuename2 - second parameter namevalue2 - second parameter valueIOExceptionsetParameterpublic static InputStream post(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException
name1 - first parameter namevalue1 - first parameter valuename2 - second parameter namevalue2 - second parameter valuename3 - third parameter namevalue3 - third parameter valueIOExceptionsetParameterpublic static InputStream post(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException
name1 - first parameter namevalue1 - first parameter valuename2 - second parameter namevalue2 - second parameter valuename3 - third parameter namevalue3 - third parameter valuename4 - fourth parameter namevalue4 - fourth parameter valueIOExceptionsetParameterCopyright © 2018 universAAL Consortium. All rights reserved.