public class UrlConnection extends java.lang.Object implements IConnection
Constructor and Description |
---|
UrlConnection(IHttpRequest request)
Creates a new UrlConnection
|
Modifier and Type | Method and Description |
---|---|
void |
addRequestHeader(java.lang.String headerName,
java.lang.String headerValue)
Adds a header to the connection (Must be done before reading/writing)
|
void |
close()
Closes this connection, and all streams become inaccessible
|
int |
getContentLength()
Returns the Content-Length
|
java.util.Map<java.lang.String,java.lang.String> |
getHeaders()
Gets the response headers for this connection
|
java.io.InputStream |
getInputStream()
Gets the stream to read to the response
|
java.io.OutputStream |
getOutputStream()
Gets the stream to write to the request
|
java.lang.String |
getRequestMethod()
Gets the HTTP request method
|
int |
getResponseCode()
Gets the response code for the request
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaders() |
java.lang.String |
getResponseMessage()
Get the response message
|
void |
setConnectTimeout(int connectTimeoutMilliseconds)
Set the connect timeout on the connection
|
void |
setContentLength(int length)
Set the Content-Length header
|
void |
setFollowRedirects(boolean followRedirects)
Follow 3XX series redirects
|
void |
setReadTimeout(int readTimeoutMilliseconds)
Set the read timeout on the connection
|
public UrlConnection(IHttpRequest request) throws java.io.IOException
request
- the IHttpRequest to create the connection fromjava.io.IOException
- an exception occurs if there was a problem creating the connectionpublic void setFollowRedirects(boolean followRedirects)
IConnection
setFollowRedirects
in interface IConnection
followRedirects
- true to follow redirects, false otherwisepublic void addRequestHeader(java.lang.String headerName, java.lang.String headerValue)
IConnection
addRequestHeader
in interface IConnection
headerName
- the header nameheaderValue
- the header valuepublic java.io.OutputStream getOutputStream() throws java.io.IOException
IConnection
getOutputStream
in interface IConnection
java.io.IOException
- if something goes wrong while getting the streampublic java.io.InputStream getInputStream() throws java.io.IOException
IConnection
getInputStream
in interface IConnection
java.io.IOException
- if something goes wrong while getting the streampublic int getContentLength()
IConnection
getContentLength
in interface IConnection
public int getResponseCode() throws java.io.IOException
IConnection
getResponseCode
in interface IConnection
java.io.IOException
- if something goes wrong while getting the response codepublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaders()
getResponseHeaders
in interface IConnection
public java.lang.String getResponseMessage() throws java.io.IOException
IConnection
getResponseMessage
in interface IConnection
java.io.IOException
- if something goes wrong while getting the response messagepublic void close()
IConnection
close
in interface IConnection
public java.util.Map<java.lang.String,java.lang.String> getHeaders()
IConnection
getHeaders
in interface IConnection
public java.lang.String getRequestMethod()
IConnection
getRequestMethod
in interface IConnection
public void setContentLength(int length)
IConnection
setContentLength
in interface IConnection
length
- the length of contentpublic void setReadTimeout(int readTimeoutMilliseconds)
IConnection
setReadTimeout
in interface IConnection
readTimeoutMilliseconds
- the read timeout in millisecondspublic void setConnectTimeout(int connectTimeoutMilliseconds)
IConnection
setConnectTimeout
in interface IConnection
connectTimeoutMilliseconds
- the connection timeout in milliseconds