Fields Summary |
---|
private String[] | methodTokens |
protected String | methodThe HTTP request method of this {@code HttpURLConnection}. The default
value is {@code "GET"}. |
protected int | responseCodeThe status code of the response obtained from the HTTP request. The
default value is {@code -1}.
1xx: Informational
2xx: Success
3xx: Relocation/Redirection
4xx: Client Error
5xx: Server Error
|
protected String | responseMessageThe HTTP response message which corresponds to the response code. |
protected boolean | instanceFollowRedirectsFlag to define whether the protocol will automatically follow redirects
or not. The default value is {@code true}. |
private static boolean | followRedirects |
protected int | chunkLengthIf the HTTP chunked encoding is enabled this parameter defines the
chunk-length. Default value is {@code -1} that means the chunked encoding
mode is disabled. |
protected int | fixedContentLengthIf using HTTP fixed-length streaming mode this parameter defines the
fixed length of content. Default value is {@code -1} that means the
fixed-length streaming mode is disabled. |
private static final int | DEFAULT_CHUNK_LENGTH |
public static final int | HTTP_ACCEPTEDNumeric status code, 202: Accepted |
public static final int | HTTP_BAD_GATEWAYNumeric status code, 502: Bad Gateway |
public static final int | HTTP_BAD_METHODNumeric status code, 405: Bad Method |
public static final int | HTTP_BAD_REQUESTNumeric status code, 400: Bad Request |
public static final int | HTTP_CLIENT_TIMEOUTNumeric status code, 408: Client Timeout |
public static final int | HTTP_CONFLICTNumeric status code, 409: Conflict |
public static final int | HTTP_CREATEDNumeric status code, 201: Created |
public static final int | HTTP_ENTITY_TOO_LARGENumeric status code, 413: Entity too large |
public static final int | HTTP_FORBIDDENNumeric status code, 403: Forbidden |
public static final int | HTTP_GATEWAY_TIMEOUTNumeric status code, 504: Gateway timeout |
public static final int | HTTP_GONENumeric status code, 410: Gone |
public static final int | HTTP_INTERNAL_ERRORNumeric status code, 500: Internal error |
public static final int | HTTP_LENGTH_REQUIREDNumeric status code, 411: Length required |
public static final int | HTTP_MOVED_PERMNumeric status code, 301 Moved permanently |
public static final int | HTTP_MOVED_TEMPNumeric status code, 302: Moved temporarily |
public static final int | HTTP_MULT_CHOICENumeric status code, 300: Multiple choices |
public static final int | HTTP_NO_CONTENTNumeric status code, 204: No content |
public static final int | HTTP_NOT_ACCEPTABLENumeric status code, 406: Not acceptable |
public static final int | HTTP_NOT_AUTHORITATIVENumeric status code, 203: Not authoritative |
public static final int | HTTP_NOT_FOUNDNumeric status code, 404: Not found |
public static final int | HTTP_NOT_IMPLEMENTEDNumeric status code, 501: Not implemented |
public static final int | HTTP_NOT_MODIFIEDNumeric status code, 304: Not modified |
public static final int | HTTP_OKNumeric status code, 200: OK |
public static final int | HTTP_PARTIALNumeric status code, 206: Partial |
public static final int | HTTP_PAYMENT_REQUIREDNumeric status code, 402: Payment required |
public static final int | HTTP_PRECON_FAILEDNumeric status code, 412: Precondition failed |
public static final int | HTTP_PROXY_AUTHNumeric status code, 407: Proxy authentication required |
public static final int | HTTP_REQ_TOO_LONGNumeric status code, 414: Request too long |
public static final int | HTTP_RESETNumeric status code, 205: Reset |
public static final int | HTTP_SEE_OTHERNumeric status code, 303: See other |
public static final int | HTTP_SERVER_ERRORNumeric status code, 500: Internal error |
public static final int | HTTP_USE_PROXYNumeric status code, 305: Use proxy |
public static final int | HTTP_UNAUTHORIZEDNumeric status code, 401: Unauthorized |
public static final int | HTTP_UNSUPPORTED_TYPENumeric status code, 415: Unsupported type |
public static final int | HTTP_UNAVAILABLENumeric status code, 503: Unavailable |
public static final int | HTTP_VERSIONNumeric status code, 505: Version not supported |
Methods Summary |
---|
public abstract void | disconnect()Closes the connection to the HTTP server.
|
public java.io.InputStream | getErrorStream()Returns an input stream from the server in the case of an error such as
the requested file has not been found on the remote server. This stream
can be used to read the data the server will send back.
return null;
|
public static boolean | getFollowRedirects()Returns the value of {@code followRedirects} which indicates if this
connection follows a different URL redirected by the server. It is
enabled by default.
return followRedirects;
|
public long | getHeaderFieldDate(java.lang.String field, long defaultValue)Returns the date value in milliseconds since {@code 01.01.1970, 00:00h}
corresponding to the header field {@code field}. The {@code defaultValue}
will be returned if no such field can be found in the response header.
return super.getHeaderFieldDate(field, defaultValue);
|
public boolean | getInstanceFollowRedirects()Returns whether this connection follows redirects.
return instanceFollowRedirects;
|
public java.security.Permission | getPermission()Returns the permission object (in this case {@code SocketPermission})
with the host and the port number as the target name and {@code
"resolve, connect"} as the action list. If the port number of this URL
instance is lower than {@code 0} the port will be set to {@code 80}.
int port = url.getPort();
if (port < 0) {
port = 80;
}
return new SocketPermission(url.getHost() + ":" + port, //$NON-NLS-1$
"connect, resolve"); //$NON-NLS-1$
|
public java.lang.String | getRequestMethod()Returns the request method which will be used to make the request to the
remote HTTP server. All possible methods of this HTTP implementation is
listed in the class definition.
return method;
|
public int | getResponseCode()Returns the response code returned by the remote HTTP server.
// Call getInputStream() first since getHeaderField() doesn't return
// exceptions
getInputStream();
String response = getHeaderField(0);
if (response == null) {
return -1;
}
response = response.trim();
int mark = response.indexOf(" ") + 1; //$NON-NLS-1$
if (mark == 0) {
return -1;
}
int last = mark + 3;
if (last > response.length()) {
last = response.length();
}
responseCode = Integer.parseInt(response.substring(mark, last));
if (last + 1 <= response.length()) {
responseMessage = response.substring(last + 1);
}
return responseCode;
|
public java.lang.String | getResponseMessage()Returns the response message returned by the remote HTTP server.
if (responseMessage != null) {
return responseMessage;
}
getResponseCode();
return responseMessage;
|
public void | setChunkedStreamingMode(int chunklen)If the length of a HTTP request body is NOT known ahead, enable chunked
transfer encoding to enable streaming with buffering. Notice that not all
http servers support this mode. Sets after connection will cause an
exception.
if (super.connected) {
throw new IllegalStateException(Msg.getString("K0079")); //$NON-NLS-1$
}
if (0 <= fixedContentLength) {
throw new IllegalStateException(Msg.getString("KA003")); //$NON-NLS-1$
}
if (0 >= chunklen) {
chunkLength = DEFAULT_CHUNK_LENGTH;
} else {
chunkLength = chunklen;
}
|
public void | setFixedLengthStreamingMode(int contentLength)If the length of a HTTP request body is known ahead, sets fixed length to
enable streaming without buffering. Sets after connection will cause an
exception.
if (super.connected) {
throw new IllegalStateException(Msg.getString("K0079")); //$NON-NLS-1$
}
if (0 < chunkLength) {
throw new IllegalStateException(Msg.getString("KA003")); //$NON-NLS-1$
}
if (0 > contentLength) {
throw new IllegalArgumentException(Msg.getString("K0051")); //$NON-NLS-1$
}
this.fixedContentLength = contentLength;
|
public static void | setFollowRedirects(boolean auto)Sets the flag of whether this connection will follow redirects returned
by the remote server. This method can only be called with the permission
from the security manager.
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSetFactory();
}
followRedirects = auto;
|
public void | setInstanceFollowRedirects(boolean followRedirects)Sets whether this connection follows redirects.
instanceFollowRedirects = followRedirects;
|
public void | setRequestMethod(java.lang.String method)Sets the request command which will be sent to the remote HTTP server.
This method can only be called before the connection is made.
if (connected) {
throw new ProtocolException(Msg.getString("K0037")); //$NON-NLS-1$
}
for (int i = 0; i < methodTokens.length; i++) {
if (methodTokens[i].equals(method)) {
// if there is a supported method that matches the desired
// method, then set the current method and return
this.method = methodTokens[i];
return;
}
}
// if none matches, then throw ProtocolException
throw new ProtocolException();
|
public abstract boolean | usingProxy()Returns whether this connection uses a proxy server or not.
|