Package nzilbb.labbcat.http
Class HttpRequestPostMultipart
- java.lang.Object
-
- nzilbb.labbcat.http.HttpRequestPostMultipart
-
public class HttpRequestPostMultipart extends Object
Multpart POST HTTP Request classOriginally com.myjavatools.web.ClientHttpRequest (version 1.0) by Vlad Patryshev
Adapted for LaBB-CAT by Robert Fromont
-
-
Constructor Summary
Constructors Constructor Description HttpRequestPostMultipart(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancel the current requestbooleanisCancelling()Determines whether or not the request is being cancelled.HttpURLConnectionpost()posts the requests to the server, with all the cookies and parameters that were addedHttpURLConnectionpost(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 argumentHttpURLConnectionpost(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 argumentsHttpURLConnectionpost(String name, Object value)post the POST request to the server, with the specified parameterHttpURLConnectionpost(String name1, Object value1, String name2, Object value2)post the POST request to the server, with the specified parametersHttpURLConnectionpost(String name1, Object value1, String name2, Object value2, String name3, Object value3)post the POST request to the server, with the specified parametersHttpURLConnectionpost(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 HttpURLConnectionpost(URL url, String sAuthorization, Object[] parameters)posts a new request to specified URL, with parameters that are passed in the argumentstatic HttpURLConnectionpost(URL url, String sAuthorization, String[] cookies, Object[] parameters)posts a new request to specified URL, with cookies and parameters that are passed in the argumentstatic HttpURLConnectionpost(URL url, String sAuthorization, String name1, Object value1)post the POST request specified URL, with the specified parameterstatic HttpURLConnectionpost(URL url, String sAuthorization, String name1, Object value1, String name2, Object value2)post the POST request to specified URL, with the specified parametersstatic HttpURLConnectionpost(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 HttpURLConnectionpost(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 HttpURLConnectionpost(URL url, String sAuthorization, Map<String,String> parameters)posts a new request to specified URL, with parameters that are passed in the argumentstatic HttpURLConnectionpost(URL url, String sAuthorization, Map<String,String> cookies, Map<String,String> parameters)posts a new request to specified URL, with cookies and parameters that are passed in the argumentHttpURLConnectionpost(Map<String,String> 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 argumentHttpURLConnectionpost(Map<String,String> cookies, Map<String,String> 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 argumentsvoidsetCookie(String name, String value)adds a cookie to the requstvoidsetCookies(String[] cookies)adds cookies to the requestvoidsetCookies(Map<String,String> cookies)adds cookies to the requestHttpRequestPostMultipartsetHeader(String sKey, String sValue)Sets a request parameter valueHttpRequestPostMultipartsetLanguage(String language)Set the Accept-Language header with the given language code, if any.,HttpRequestPostMultipartsetParameter(String name, File file)adds a file parameter to the requestHttpRequestPostMultipartsetParameter(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 requestHttpRequestPostMultipartsetParameter(String name, String value)adds a string parameter to the requestHttpRequestPostMultipartsetParameter(String name, String filename, InputStream is)adds a file parameter to the requestHttpRequestPostMultipartsetParameters(Object[] parameters)adds parameters to the requestHttpRequestPostMultipartsetParameters(Map<String,String> parameters)adds parameters to the requestHttpRequestPostMultipartsetUserAgent()Sets the user-agent header to indicate the name/version of the library.StringtoString()String representation of the request, for logging.
-
-
-
Constructor Detail
-
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
public HttpRequestPostMultipart(URL url, String sAuthorization) throws IOException
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
public HttpRequestPostMultipart(String urlString, String sAuthorization) throws IOException
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 Detail
-
setHeader
public HttpRequestPostMultipart setHeader(String sKey, String sValue)
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
public HttpRequestPostMultipart 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
public HttpRequestPostMultipart setLanguage(String language)
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
public void setCookie(String name, String value) throws IOException
adds a cookie to the requst- Parameters:
name- cookie namevalue- cookie value- Throws:
IOException- If an IO error occurs.
-
setCookies
public void setCookies(Map<String,String> cookies) throws IOException
adds cookies to the request- Parameters:
cookies- the cookie "name-to-value" map- Throws:
IOException- If an IO error occurs.
-
setCookies
public void setCookies(String[] cookies) throws IOException
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
public HttpRequestPostMultipart setParameter(String name, String value) throws IOException
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
public HttpRequestPostMultipart setParameter(String name, File file) throws IOException
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
public HttpRequestPostMultipart setParameter(String name, Object object) throws IOException
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
public HttpRequestPostMultipart setParameters(Map<String,String> parameters) throws IOException
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
public HttpRequestPostMultipart setParameters(Object[] parameters) throws IOException
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
public HttpURLConnection post() throws IOException
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
public HttpURLConnection post(Map<String,String> parameters) throws IOException
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:
setParameters(java.util.Map<java.lang.String, java.lang.String>)
-
post
public HttpURLConnection post(Object[] parameters) throws IOException
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:
setParameters(java.util.Map<java.lang.String, java.lang.String>)
-
post
public HttpURLConnection post(Map<String,String> cookies, Map<String,String> parameters) throws IOException
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:
setParameters(java.util.Map<java.lang.String, java.lang.String>),setCookies(java.util.Map<java.lang.String, java.lang.String>)
-
post
public HttpURLConnection post(String[] cookies, Object[] parameters) throws IOException
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:
setParameters(java.util.Map<java.lang.String, java.lang.String>),setCookies(java.util.Map<java.lang.String, java.lang.String>)
-
post
public HttpURLConnection post(String name, Object value) throws IOException
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:
setParameter(java.lang.String, java.lang.String)
-
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:
setParameter(java.lang.String, java.lang.String)
-
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:
setParameter(java.lang.String, java.lang.String)
-
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:
setParameter(java.lang.String, java.lang.String)
-
post
public static HttpURLConnection post(URL url, String sAuthorization, Map<String,String> 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:
setParameters(java.util.Map<java.lang.String, java.lang.String>)
-
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:
setParameters(java.util.Map<java.lang.String, java.lang.String>)
-
post
public static HttpURLConnection post(URL url, String sAuthorization, Map<String,String> cookies, Map<String,String> 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 occurd.- See Also:
setCookies(java.util.Map<java.lang.String, java.lang.String>),setParameters(java.util.Map<java.lang.String, java.lang.String>)
-
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:
setCookies(java.util.Map<java.lang.String, java.lang.String>),setParameters(java.util.Map<java.lang.String, java.lang.String>)
-
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:
setParameter(java.lang.String, java.lang.String)
-
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:
setParameter(java.lang.String, java.lang.String)
-
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:
setParameter(java.lang.String, java.lang.String)
-
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:
setParameter(java.lang.String, java.lang.String)
-
-