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.
|
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.lang.String |
getResponseMessage()
Get the response message.
|
void |
setContentLength(int length)
Set the Content-Length header
|
void |
setFollowRedirects(boolean followRedirects)
Follow 3XX series redirects.
|
public UrlConnection(IHttpRequest request) throws java.io.IOException
request - The IHttpRequest to create the connection from.java.io.IOException - An exception occurs if there was a problem creating the connection.public void setFollowRedirects(boolean followRedirects)
IConnectionsetFollowRedirects in interface IConnectionfollowRedirects - true to follow redirects, false otherwise.public void addRequestHeader(java.lang.String headerName,
java.lang.String headerValue)
IConnectionaddRequestHeader in interface IConnectionheaderName - The header name.headerValue - The header value.public java.io.OutputStream getOutputStream()
throws java.io.IOException
IConnectiongetOutputStream in interface IConnectionjava.io.IOException - if something goes wrong while getting the stream.public java.io.InputStream getInputStream()
throws java.io.IOException
IConnectiongetInputStream in interface IConnectionjava.io.IOException - if something goes wrong while getting the stream.public int getResponseCode()
throws java.io.IOException
IConnectiongetResponseCode in interface IConnectionjava.io.IOException - if something goes wrong while getting the response code.public java.lang.String getResponseMessage()
throws java.io.IOException
IConnectiongetResponseMessage in interface IConnectionjava.io.IOException - if something goes wrong while getting the response message.public 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 content