Package com.articulate.sigma
Class ClientHttpRequest
java.lang.Object
com.articulate.sigma.ClientHttpRequest
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.
- Version:
- 1.0 Copyright 2007 Vlad Patryshev Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Author:
- Vlad Patryshev
-
Constructor Summary
ConstructorsConstructorDescriptionClientHttpRequest(String urlString) Creates a new multipart POST HTTP request for a specified URL stringClientHttpRequest(URL url) Creates a new multipart POST HTTP request for a specified URLClientHttpRequest(URLConnection connection) Creates a new multipart POST HTTP request on a freshly opened URLConnection -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconnect()protected voidnewline()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 InputStreamposts a new request to specified URL, with parameters that are passed in the argumentstatic InputStreamposts a new request to specified URL, with cookies and parameters that are passed in the argumentstatic InputStreampost the POST request specified URL, with the specified parameterstatic InputStreampost the POST request to specified URL, with the specified parametersstatic InputStreampost(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3) post the POST request to specified URL, with the specified parametersstatic InputStreampost(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 parametersstatic InputStreamposts a new request to specified URL, with parameters that are passed in the argumentstatic InputStreamposts 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 argumentsprotected static Stringvoidadds a cookie to the requstvoidsetCookies(String[] cookies) adds cookies to the requestvoidsetCookies(Map<String, String> cookies) adds cookies to the requestvoidsetParameter(String name, File file) adds a file parameter to the requestvoidsetParameter(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 requestvoidsetParameter(String name, String value) adds a string parameter to the requestvoidsetParameter(String name, String filename, InputStream is) adds a file parameter to the requestvoidsetParameters(Object[] parameters) adds parameters to the requestvoidsetParameters(Map parameters) adds parameters to the requestprotected voidwrite(char c) protected voidprotected void
-
Constructor Details
-
ClientHttpRequest
Creates a new multipart POST HTTP request on a freshly opened URLConnection- Parameters:
connection- an already open URL connection- Throws:
IOException
-
ClientHttpRequest
Creates a new multipart POST HTTP request for a specified URL- Parameters:
url- the URL to send request to- Throws:
IOException
-
ClientHttpRequest
Creates a new multipart POST HTTP request for a specified URL string- Parameters:
urlString- the string representation of the URL to send request to- Throws:
IOException
-
-
Method Details
-
connect
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
newline
- Throws:
IOException
-
writeln
- Throws:
IOException
-
randomString
-
setCookie
adds a cookie to the requst- Parameters:
name- cookie namevalue- cookie value- Throws:
IOException
-
setCookies
adds cookies to the request- Parameters:
cookies- the cookie "name-to-value" map- Throws:
IOException
-
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
-
setParameter
adds a string parameter to the request- Parameters:
name- parameter namevalue- parameter value- Throws:
IOException
-
setParameter
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- Throws:
IOException
-
setParameter
adds a file parameter to the request- Parameters:
name- parameter namefile- the file to upload- Throws:
IOException
-
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- Throws:
IOException
-
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- Throws:
IOException
-
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- Throws:
IOException
-
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
-
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- 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- 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- 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- 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- See Also:
-
post
public InputStream 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- See Also:
-
post
public InputStream 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- See Also:
-
post
public InputStream 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- See Also:
-
post
posts a new request to specified URL, with parameters that are passed in the argument- Parameters:
parameters- request parameters- Returns:
- input stream with the server response
- Throws:
IOException- See Also:
-
post
posts a new request to specified URL, with parameters that are passed in the argument- Parameters:
parameters- request parameters- Returns:
- input stream with the server response
- Throws:
IOException- See Also:
-
post
public static InputStream post(URL url, Map<String, String> cookies, Map parameters) throws IOExceptionposts a new request to specified URL, with cookies and parameters that are passed in the argument- Parameters:
cookies- request cookiesparameters- request parameters- Returns:
- input stream with the server response
- Throws:
IOException- See Also:
-
post
posts a new request to specified URL, with cookies and parameters that are passed in the argument- Parameters:
cookies- request cookiesparameters- request parameters- Returns:
- input stream with the server response
- Throws:
IOException- See Also:
-
post
post the POST request specified URL, with the specified parameter- Parameters:
name1- parameter namevalue1- parameter value- Returns:
- input stream with the server response
- Throws:
IOException- See Also:
-
post
public static InputStream post(URL url, String name1, Object value1, String name2, Object value2) throws IOException post the POST request to specified URL, 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- See Also:
-
post
public static InputStream post(URL url, 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:
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- See Also:
-
post
public static InputStream post(URL url, 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:
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- See Also:
-