public class Outcall extends Object
This is basically a thin wrapper over HttpURLConnection which adds some boilder plate code and a bit of logging / monitoring.
| Constructor and Description |
|---|
Outcall(URL url)
Creates a new Outcall to the given URL.
|
| Modifier and Type | Method and Description |
|---|---|
Charset |
getContentEncoding()
Returns the charset used by the server to encode the response.
|
String |
getData()
Returns the result of the call as String.
|
String |
getHeaderField(String name)
Returns the response header with the given name.
|
InputStream |
getInput()
Provides access to the result of the call.
|
OutputStream |
getOutput()
Provides access to the input of the call.
|
Outcall |
postData(Context params,
Charset charset)
Sents the given context as POST to the designated server.
|
void |
setAuthParams(String user,
String password)
Sets the HTTP Authorization header.
|
void |
setConnectTimeout(int timeoutMillis)
Sets a specified timeout value, in milliseconds, to be used
when opening a communications link to the resource referenced
by this outcall.
|
void |
setCookie(String name,
String value)
Sets a HTTP cookie
|
void |
setReadTimeout(int timeoutMillis)
Sets the read timeout to a specified timeout, in
milliseconds.
|
void |
setRequestProperty(String name,
String value)
Sets the header of the HTTP call.
|
public Outcall(URL url) throws IOException
url - the url to callIOException - in case of any IO errorpublic Outcall postData(Context params, Charset charset) throws IOException
params - the data to POSTcharset - the charset to use when encoding the post dataIOException - in case of any IO errorpublic InputStream getInput() throws IOException
Once this method is called, the call will be started and data will be read.
IOException - in case of any IO errorpublic OutputStream getOutput() throws IOException
IOException - in case of any IO errorpublic void setRequestProperty(String name, String value)
name - name of the header to setvalue - value of the header to setpublic void setAuthParams(String user, String password) throws IOException
user - the username to usepassword - the password to useIOException - in case of any IO errorpublic void setConnectTimeout(int timeoutMillis)
timeoutMillis - specifies the connect timeout value in millisecondspublic void setReadTimeout(int timeoutMillis)
timeoutMillis - specifies the timeout value to be used in millisecondspublic String getData() throws IOException
IOException - in case of any IO error@Nullable public String getHeaderField(String name)
name - the name of the header to fetchpublic Charset getContentEncoding()
Copyright © 2018. All rights reserved.