Package nzilbb.labbcat.http
Class HttpRequestPost
- java.lang.Object
-
- nzilbb.labbcat.http.HttpRequestPost
-
public class HttpRequestPost extends Object
POST HTTP request.Originally com.myjavatools.web.ClientHttpRequest (version 1.0) by Vlad Patryshev
Adapted for LaBB-CAT by Robert Fromont
-
-
Constructor Summary
Constructors Constructor Description HttpRequestPost(String urlString, String sAuthorization)Creates a new POST HTTP request for a specified URL stringHttpRequestPost(HttpURLConnection connection, String sAuthorization)Creates a new POST HTTP request on a freshly opened URLConnectionHttpRequestPost(URL url, String sAuthorization)Creates a new POST HTTP request for a specified URL
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 body)posts the requests to the server, with all the cookies and parameters that were addedHttpURLConnectionpost(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 argumentsHttpURLConnectionpost(javax.json.JsonObject json)posts the requests to the server, with all the cookies and parameters that were addedHttpRequestPostsetCookie(String name, String value)adds a cookie to the requstHttpRequestPostsetCookies(String[] cookies)adds cookies to the requestHttpRequestPostsetCookies(Map<String,String> cookies)adds cookies to the requestHttpRequestPostsetHeader(String sKey, String sValue)Sets a request parameter valueHttpRequestPostsetLanguage(String language)Set the Accept-Language header with the given language code, if any.,HttpRequestPostsetMethod(String method)Sets the HTTP method to use.HttpRequestPostsetParameter(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 requestHttpRequestPostsetParameter(String name, String value)adds a string parameter to the requestHttpRequestPostsetParameters(Object[] parameters)adds parameters to the requestHttpRequestPostsetParameters(Map<String,String> parameters)adds parameters to the requestHttpRequestPostsetUserAgent()Sets the user-agent header to indicate the name/version of the library.StringtoString()String representation of the request, for logging.
-
-
-
Constructor Detail
-
HttpRequestPost
public HttpRequestPost(HttpURLConnection connection, String sAuthorization) throws IOException
Creates a new 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.
-
HttpRequestPost
public HttpRequestPost(URL url, String sAuthorization) throws IOException
Creates a new 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.
-
HttpRequestPost
public HttpRequestPost(String urlString, String sAuthorization) throws IOException
Creates a new 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 HttpRequestPost 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.
-
setUserAgent
public HttpRequestPost 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 HttpRequestPost 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.
-
setMethod
public HttpRequestPost setMethod(String method) throws IOException
Sets the HTTP method to use.- Parameters:
method- "POST", "PUT", "DELETE", etc.- Returns:
- A reference to this object.
- Throws:
IOException- If an IO error occurs.
-
setCookie
public HttpRequestPost setCookie(String name, String value) throws IOException
adds a cookie to the requst- Parameters:
name- cookie namevalue- cookie value- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException- If an IO error occurs.
-
setCookies
public HttpRequestPost setCookies(Map<String,String> cookies) throws IOException
adds cookies to the request- Parameters:
cookies- the cookie "name-to-value" map- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException- If an IO error occurs.
-
setCookies
public HttpRequestPost 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)- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException- If an IO error occurs.
-
setParameter
public HttpRequestPost 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 HttpRequestPost 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, or a collection of values- Returns:
- A reference to this object, so that setters can be chained.
- Throws:
IOException- If an IO error occurs.
-
setParameters
public HttpRequestPost 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 HttpRequestPost 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(javax.json.JsonObject json) throws IOException
posts the requests to the server, with all the cookies and parameters that were added- Parameters:
json- JSON body t post.- Returns:
- input stream with the server response
- Throws:
IOException- If an IO error occurs.
-
post
public HttpURLConnection post(String body) throws IOException
posts the requests to the server, with all the cookies and parameters that were added- Parameters:
body- Body text to post.- 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- Authorition 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 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[] 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)
-
-