Package nzilbb.labbcat.http
Class HttpRequestPost
java.lang.Object
nzilbb.labbcat.http.HttpRequestPost
POST HTTP request.
Originally com.myjavatools.web.ClientHttpRequest (version 1.0) by Vlad Patryshev
Adapted for LaBB-CAT by Robert Fromont
-
Constructor Summary
ConstructorsConstructorDescriptionHttpRequestPost
(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
Modifier and TypeMethodDescriptionpost()
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 addedposts 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 argumentspost
(javax.json.JsonObject json) posts the requests to the server, with all the cookies and parameters that were addedadds a cookie to the requstsetCookies
(String[] cookies) adds cookies to the requestsetCookies
(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.,Sets the HTTP method to use.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 requestsetParameter
(String name, String value) adds a string 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
-
HttpRequestPost
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
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
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 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.
-
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.
-
setMethod
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
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
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
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
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
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
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- Parameters:
json
- JSON body t post.- 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- Parameters:
body
- Body text to post.- 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
- Authorition 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 occurs.- 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.
-