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 connectionIOException
public ClientHttpRequest(URL url) throws IOException
url
- the URL to send request toIOException
public ClientHttpRequest(String urlString) throws IOException
urlString
- the string representation of the URL to send request toIOException
protected void connect() throws IOException
IOException
protected void write(char c) throws IOException
IOException
protected void write(String s) throws IOException
IOException
protected void newline() throws IOException
IOException
protected void writeln(String s) throws IOException
IOException
protected static String randomString()
public void setCookie(String name, String value) throws IOException
name
- cookie namevalue
- cookie valueIOException
public void setCookies(Map cookies) throws IOException
cookies
- the cookie "name-to-value" mapIOException
public 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)IOException
public void setParameter(String name, String value) throws IOException
name
- parameter namevalue
- parameter valueIOException
public 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 fromIOException
public void setParameter(String name, File file) throws IOException
name
- parameter namefile
- the file to uploadIOException
public void setParameter(String name, Object object) throws IOException
name
- parameter nameobject
- parameter value, a File or anything else that can be
stringifiedIOException
public 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
requestIOException
public 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 requestIOException
public InputStream post() throws IOException
IOException
public InputStream post(Map parameters) throws IOException
parameters
- request parametersIOException
setParameters
public InputStream post(Object[] parameters) throws IOException
parameters
- request parametersIOException
setParameters
public InputStream post(Map cookies, Map parameters) throws IOException
cookies
- request cookiesparameters
- request parametersIOException
setParameters
,
setCookies
public InputStream post(String[] cookies, Object[] parameters) throws IOException
cookies
- request cookiesparameters
- request parametersIOException
setParameters
,
setCookies
public InputStream post(String name, Object value) throws IOException
name
- parameter namevalue
- parameter valueIOException
setParameter
public InputStream post(String name1, Object value1, String name2, Object value2) throws IOException
name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter valueIOException
setParameter
public 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 valueIOException
setParameter
public 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 valueIOException
setParameter
public static InputStream post(URL url, Map parameters) throws IOException
parameters
- request parametersIOException
setParameters
public static InputStream post(URL url, Object[] parameters) throws IOException
parameters
- request parametersIOException
setParameters
public static InputStream post(URL url, Map cookies, Map parameters) throws IOException
cookies
- request cookiesparameters
- request parametersIOException
setCookies
,
setParameters
public static InputStream post(URL url, String[] cookies, Object[] parameters) throws IOException
cookies
- request cookiesparameters
- request parametersIOException
setCookies
,
setParameters
public static InputStream post(URL url, String name1, Object value1) throws IOException
name
- parameter namevalue
- parameter valueIOException
setParameter
public 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 valueIOException
setParameter
public 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 valueIOException
setParameter
public 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 valueIOException
setParameter
Copyright © 2018 universAAL Consortium. All rights reserved.