Package nzilbb.labbcat.http
Class HttpRequestPostMultipart
java.lang.Object
nzilbb.labbcat.http.HttpRequestPostMultipart
Multpart POST HTTP Request class
Originally com.myjavatools.web.ClientHttpRequest (version 1.0) by Vlad Patryshev
Adapted for LaBB-CAT by Robert Fromont
-
Constructor Summary
ConstructorsConstructorDescriptionHttpRequestPostMultipart
(String urlString, String sAuthorization) Creates a new multipart POST HTTP request for a specified URL stringHttpRequestPostMultipart
(HttpURLConnection connection, String sAuthorization) Creates a new multipart POST HTTP request on a freshly opened URLConnectionHttpRequestPostMultipart
(URL url, String sAuthorization) Creates a new multipart POST HTTP request for a specified URL -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancel the current requestboolean
Determines whether or not the request is being cancelled.post()
posts the requests to the server, with all the cookies and parameters that were addedposts 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 argumentposts 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 argumentspost the POST request to the server, with the specified parameterpost the POST request to the server, with the specified parameterspost the POST request to the server, with the specified parameterspost
(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 parametersstatic HttpURLConnection
posts a new request to specified URL, with parameters that are passed in the argumentstatic HttpURLConnection
posts a new request to specified URL, with cookies and parameters that are passed in the argumentstatic HttpURLConnection
post the POST request specified URL, with the specified parameterstatic HttpURLConnection
post the POST request to specified URL, with the specified parametersstatic HttpURLConnection
post
(URL url, String sAuthorization, String name1, Object value1, String name2, Object value2, String name3, Object value3) post the POST request to specified URL, with the specified parametersstatic HttpURLConnection
post
(URL url, String sAuthorization, 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 parametersstatic HttpURLConnection
posts a new request to specified URL, with parameters that are passed in the argumentstatic HttpURLConnection
posts a new request to specified URL, with cookies and parameters that are passed in the argumentposts 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 argumentposts 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 argumentsvoid
adds a cookie to the requstvoid
setCookies
(String[] cookies) adds cookies to the requestvoid
setCookies
(Map<String, String> cookies) adds cookies to the requestSets a request parameter valuesetLanguage
(String language) Set the Accept-Language header with the given language code, if any.,setParameter
(String name, File file) adds a file parameter to the requestsetParameter
(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 requestsetParameter
(String name, String value) adds a string parameter to the requestsetParameter
(String name, String filename, InputStream is) adds a file parameter to the requestsetParameters
(Object[] parameters) adds parameters to the requestsetParameters
(Map<String, String> parameters) adds parameters to the requestSets the user-agent header to indicate the name/version of the library.toString()
String representation of the request, for logging.
-
Constructor Details
-
HttpRequestPostMultipart
public HttpRequestPostMultipart(HttpURLConnection connection, String sAuthorization) throws IOException Creates a new multipart POST HTTP request on a freshly opened URLConnection- Parameters:
connection
- an already open URL connectionsAuthorization
- Authorisation string or null if none is required- Throws:
IOException
- If an IO error occurs.
-
HttpRequestPostMultipart
Creates a new multipart POST HTTP request for a specified URL- Parameters:
url
- the URL to send request tosAuthorization
- Authorisation string or null if none is required- Throws:
IOException
- If an IO error occurs.
-
HttpRequestPostMultipart
Creates a new multipart POST HTTP request for a specified URL string- Parameters:
urlString
- the string representation of the URL to send request tosAuthorization
- Authoriztion header to use.- Throws:
IOException
- If an IO error occurs.
-
-
Method Details
-
setHeader
Sets a request parameter value- Parameters:
sKey
- The header name.sValue
- The header value.- Returns:
- A reference to this object, so that setters can be chained.
-
isCancelling
public boolean isCancelling()Determines whether or not the request is being cancelled.- Returns:
- true, if the last request has been asked to cancel, false otherwise
-
cancel
public void cancel()Cancel the current request -
setUserAgent
Sets the user-agent header to indicate the name/version of the library.- Returns:
- A reference to this object, so that setters can be chained.
-
setLanguage
Set the Accept-Language header with the given language code, if any.,- Parameters:
language
- The language code, e.g. "es-AR", or null.- Returns:
- A reference to this object.
-
setCookie
adds a cookie to the requst- Parameters:
name
- cookie namevalue
- cookie value- Throws:
IOException
- If an IO error occurs.
-
setCookies
adds cookies to the request- Parameters:
cookies
- the cookie "name-to-value" map- Throws:
IOException
- If an IO error occurs.
-
setCookies
adds cookies to the request- Parameters:
cookies
- array of cookie names and values (cookies[2*i] is a name, cookies[2*i + 1] is a value)- Throws:
IOException
- If an IO error occurs.
-
setParameter
adds a string parameter to the request- Parameters:
name
- parameter namevalue
- parameter value- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException
- If an IO error occurs.
-
setParameter
public HttpRequestPostMultipart setParameter(String name, String filename, InputStream is) throws IOException adds a file parameter to the request- Parameters:
name
- parameter namefilename
- the name of the fileis
- input stream to read the contents of the file from- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException
- If an IO error occurs.
-
setParameter
adds a file parameter to the request- Parameters:
name
- parameter namefile
- the file to upload- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException
- If an IO error occurs.
-
setParameter
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- Parameters:
name
- parameter nameobject
- parameter value, a File or anything else that can be stringified- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException
- If an IO error occurs.
-
setParameters
adds parameters to the request- Parameters:
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 request- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException
- If an IO error occurs.
-
setParameters
adds parameters to the request- Parameters:
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 request- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException
- If an IO error occurs.
-
post
posts the requests to the server, with all the cookies and parameters that were added- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.
-
post
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- Parameters:
parameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
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- Parameters:
parameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public HttpURLConnection post(Map<String, String> cookies, Map<String, throws IOExceptionString> 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- Parameters:
cookies
- request cookiesparameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
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- Parameters:
cookies
- request cookiesparameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
post the POST request to the server, with the specified parameter- Parameters:
name
- parameter namevalue
- parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public HttpURLConnection post(String name1, Object value1, String name2, Object value2) throws IOException post the POST request to the server, with the specified parameters- Parameters:
name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public HttpURLConnection post(String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException post the POST request to the server, with the specified parameters- Parameters:
name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter valuename3
- third parameter namevalue3
- third parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public HttpURLConnection post(String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException post the POST request to the server, with the specified parameters- Parameters:
name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter valuename3
- third parameter namevalue3
- third parameter valuename4
- fourth parameter namevalue4
- fourth parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, Map<String, String> parameters) throws IOExceptionposts a new request to specified URL, with parameters that are passed in the argument- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.parameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, Object[] parameters) throws IOException posts a new request to specified URL, with parameters that are passed in the argument- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.parameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, Map<String, String> cookies, Map<String, throws IOExceptionString> parameters) posts a new request to specified URL, with cookies and parameters that are passed in the argument- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.cookies
- request cookiesparameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurd.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, String[] cookies, Object[] parameters) throws IOException posts a new request to specified URL, with cookies and parameters that are passed in the argument- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.cookies
- request cookiesparameters
- request parameters- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, String name1, Object value1) throws IOException post the POST request specified URL, with the specified parameter- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.name1
- parameter namevalue1
- parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, String name1, Object value1, String name2, Object value2) throws IOException post the POST request to specified URL, with the specified parameters- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException post the POST request to specified URL, with the specified parameters- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter valuename3
- third parameter namevalue3
- third parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
post
public static HttpURLConnection post(URL url, String sAuthorization, String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException post the POST request to specified URL, with the specified parameters- Parameters:
url
- URL to post to.sAuthorization
- Authoriztion header to use.name1
- first parameter namevalue1
- first parameter valuename2
- second parameter namevalue2
- second parameter valuename3
- third parameter namevalue3
- third parameter valuename4
- fourth parameter namevalue4
- fourth parameter value- Returns:
- input stream with the server response
- Throws:
IOException
- If an IO error occurs.- See Also:
-
toString
String representation of the request, for logging.
-