public class MockHttpURLConnection extends HttpURLConnection
chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessage
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
Constructor and Description |
---|
MockHttpURLConnection() |
Modifier and Type | Method and Description |
---|---|
void |
connect()
Opens a communications link to the resource referenced by this
URL, if such a connection has not already been established.
|
void |
disconnect()
Indicates that other requests to the server
are unlikely in the near future.
|
boolean |
getDoOutput()
Returns the value of this
URLConnection 's
doOutput flag. |
OutputStream |
getOutputStream()
Returns an output stream that writes to this connection.
|
String |
getRequestMethod()
Get the request method.
|
void |
setDoOutput(boolean flag)
Sets the value of the
doOutput field for this
URLConnection to the specified value. |
void |
setRequestMethod(String method)
Set the method for the URL request, one of:
GET
POST
HEAD
OPTIONS
PUT
DELETE
TRACE
are legal, subject to protocol restrictions.
|
boolean |
usingProxy()
Indicates if the connection is going through a proxy.
|
getErrorStream, getFollowRedirects, getHeaderField, getHeaderFieldDate, getHeaderFieldKey, getInstanceFollowRedirects, getPermission, getResponseCode, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getExpiration, getFileNameMap, getHeaderField, getHeaderFieldInt, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
public MockHttpURLConnection() throws MalformedURLException
MalformedURLException
public void setDoOutput(boolean flag)
URLConnection
doOutput
field for this
URLConnection
to the specified value.
A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.
setDoOutput
in class URLConnection
flag
- the new value.URLConnection.getDoOutput()
public boolean getDoOutput()
URLConnection
URLConnection
's
doOutput
flag.getDoOutput
in class URLConnection
URLConnection
's
doOutput
flag.URLConnection.setDoOutput(boolean)
public void setRequestMethod(String method)
HttpURLConnection
setRequestMethod
in class HttpURLConnection
method
- the HTTP methodHttpURLConnection.getRequestMethod()
public String getRequestMethod()
HttpURLConnection
getRequestMethod
in class HttpURLConnection
HttpURLConnection.setRequestMethod(java.lang.String)
public OutputStream getOutputStream()
URLConnection
getOutputStream
in class URLConnection
public void disconnect()
HttpURLConnection
disconnect
in class HttpURLConnection
public boolean usingProxy()
HttpURLConnection
usingProxy
in class HttpURLConnection
public void connect() throws IOException
URLConnection
If the connect
method is called when the connection
has already been opened (indicated by the connected
field having the value true
), the call is ignored.
URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
connect
in class URLConnection
SocketTimeoutException
- if the timeout expires before
the connection can be establishedIOException
- if an I/O error occurs while opening the
connection.URLConnection.connected
,
URLConnection.getConnectTimeout()
,
URLConnection.setConnectTimeout(int)