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)
IConnectionsetFollowRedirects in interface IConnectionfollowRedirects - true to follow redirects, false otherwisepublic void addRequestHeader(java.lang.String headerName,
java.lang.String headerValue)
IConnectionaddRequestHeader in interface IConnectionheaderName - the header nameheaderValue - the header valuepublic java.io.OutputStream getOutputStream()
throws java.io.IOException
IConnectiongetOutputStream in interface IConnectionjava.io.IOException - if something goes wrong while getting the streampublic java.io.InputStream getInputStream()
throws java.io.IOException
IConnectiongetInputStream in interface IConnectionjava.io.IOException - if something goes wrong while getting the streampublic int getContentLength()
IConnectiongetContentLength in interface IConnectionpublic int getResponseCode()
throws java.io.IOException
IConnectiongetResponseCode in interface IConnectionjava.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 IConnectionpublic java.lang.String getResponseMessage()
throws java.io.IOException
IConnectiongetResponseMessage in interface IConnectionjava.io.IOException - if something goes wrong while getting the response messagepublic void close()
IConnectionclose in interface IConnectionpublic java.util.Map<java.lang.String,java.lang.String> getHeaders()
IConnectiongetHeaders in interface IConnectionpublic java.lang.String getRequestMethod()
IConnectiongetRequestMethod in interface IConnectionpublic void setContentLength(int length)
IConnectionsetContentLength in interface IConnectionlength - the length of contentpublic void setReadTimeout(int readTimeoutMilliseconds)
IConnectionsetReadTimeout in interface IConnectionreadTimeoutMilliseconds - the read timeout in millisecondspublic void setConnectTimeout(int connectTimeoutMilliseconds)
IConnectionsetConnectTimeout in interface IConnectionconnectTimeoutMilliseconds - the connection timeout in milliseconds