Class HttpMethodBase
- All Implemented Interfaces:
HttpMethod
- Direct Known Subclasses:
ConnectMethod,DeleteMethod,ExpectContinueMethod,GetMethod,HeadMethod,OptionsMethod,TraceMethod
At minimum, subclasses will need to override:
getName()to return the approriate name for this method
When a method requires additional request headers, subclasses will typically want to override:
addRequestHeaders(HttpState,HttpConnection)to write those headers
When a method expects specific response headers, subclasses may want to override:
processResponseHeaders(HttpState,HttpConnection)to handle those headers
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.No-arg constructor.HttpMethodBase(String uri) Deprecated.Constructor specifying a URI. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Deprecated.Aborts the execution of this method.voidaddRequestHeader(String headerName, String headerValue) Deprecated.Adds the specified request header, NOT overwriting any previous value.voidaddRequestHeader(Header header) Deprecated.Adds the specified request header, NOT overwriting any previous value.voidaddResponseFooter(Header footer) Deprecated.Use this method internally to add footers.intexecute(HttpState state, HttpConnection conn) Deprecated.Executes this method using the specifiedHttpConnectionandHttpState.Deprecated.use #getHostAuthState()booleanDeprecated.Returns true if the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.), false otherwiseDeprecated.Returns the HTTP version used with this method (may be null if undefined, that is, the method has not been executed)booleanDeprecated.Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.Deprecated.Returns the target hostauthentication stateDeprecated.no longer applicableDeprecated.useHttpMethodParamsabstract StringgetName()Deprecated.Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".Deprecated.ReturnsHTTP protocol parametersassociated with this method.getPath()Deprecated.Gets the path of this HTTP method.Deprecated.use #getProxyAuthState()Deprecated.Returns the proxyauthentication stateDeprecated.Gets the query string of this HTTP method.intDeprecated.no longer used Returns the number of "recoverable" exceptions thrown and handled, to allow for monitoring the quality of the connection.Deprecated.Returns the character encoding of the request from the Content-Type header.getRequestHeader(String headerName) Deprecated.Returns the specified request header.Header[]Deprecated.Returns an array of the requests headers that the HTTP method currently hasHeader[]getRequestHeaders(String headerName) Deprecated.Returns the request headers with the given name.byte[]Deprecated.Returns the response body of the HTTP method, if any, as an array of bytes.byte[]getResponseBody(int maxlen) Deprecated.Returns the response body of the HTTP method, if any, as an array of bytes.Deprecated.Returns the response body of the HTTP method, if any, as anInputStream.Deprecated.Returns the response body of the HTTP method, if any, as aString.getResponseBodyAsString(int maxlen) Deprecated.Returns the response body of the HTTP method, if any, as aString.Deprecated.Returns the character encoding of the response from the Content-Type header.longDeprecated.Return the length (in bytes) of the response body, as specified in a Content-Length header.getResponseFooter(String footerName) Deprecated.Gets the response footer associated with the given name.Header[]Deprecated.Returns an array of the response footers that the HTTP method currently has in the order in which they were read.getResponseHeader(String headerName) Deprecated.Gets the response header associated with the given name.Header[]Deprecated.Returns an array of the response headers that the HTTP method currently has in the order in which they were read.Header[]getResponseHeaders(String headerName) Deprecated.Returns the response headers with the given name.intDeprecated.Returns the response status code.Deprecated.Provides access to the response status line.Deprecated.Returns the status text (or "reason phrase") associated with the latest response.getURI()Deprecated.Returns the URI of the HTTP methodbooleanbooleanDeprecated.Tests whether the execution of this method has been abortedbooleanisHttp11()Deprecated.booleanDeprecated.Returns true if the HTTP has been transmitted to the target server in its entirety, false otherwise.booleanDeprecated.UseHttpParams.setParameter(String, Object)to exercise a more granular control over HTTP protocol strictness.voidrecycle()Deprecated.no longer supported and will be removed in the future version of HttpClientvoidDeprecated.Releases the connection being used by this HTTP method.voidremoveRequestHeader(String headerName) Deprecated.Remove the request header associated with the given name.voidremoveRequestHeader(Header header) Deprecated.Removes the given request header.voidsetDoAuthentication(boolean doAuthentication) Deprecated.Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.)voidsetFollowRedirects(boolean followRedirects) Deprecated.Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)voidsetHostConfiguration(HostConfiguration hostconfig) Deprecated.no longer applicablevoidsetHttp11(boolean http11) Deprecated.voidsetMethodRetryHandler(MethodRetryHandler handler) Deprecated.useHttpMethodParamsvoidsetParams(HttpMethodParams params) Deprecated.AssignsHTTP protocol parametersfor this method.voidDeprecated.Sets the path of the HTTP method.voidsetQueryString(String queryString) Deprecated.Sets the query string of this HTTP method.voidsetQueryString(NameValuePair[] params) Deprecated.Sets the query string of this HTTP method.voidsetRequestHeader(String headerName, String headerValue) Deprecated.Set the specified request header, overwriting any previous value.voidsetRequestHeader(Header header) Deprecated.Sets the specified request header, overwriting any previous value.voidsetStrictMode(boolean strictMode) Deprecated.UseHttpParams.setParameter(String, Object)to exercise a more granular control over HTTP protocol strictness.voidDeprecated.Sets the URI for this method.booleanvalidate()Deprecated.Returns true the method is ready to execute, false otherwise.
-
Constructor Details
-
HttpMethodBase
public HttpMethodBase()Deprecated.No-arg constructor. -
HttpMethodBase
Deprecated.Constructor specifying a URI. It is responsibility of the caller to ensure that URI elements (path invalid input: '&' query parameters) are properly encoded (URL safe).- Parameters:
uri- either an absolute or relative URI. The URI is expected to be URL-encoded- Throws:
IllegalArgumentException- when URI is invalidIllegalStateException- when protocol of the absolute URI is not recognised
-
-
Method Details
-
getName
Deprecated.Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".- Specified by:
getNamein interfaceHttpMethod- Returns:
- the name of this method
-
getURI
Deprecated.Returns the URI of the HTTP method- Specified by:
getURIin interfaceHttpMethod- Returns:
- The URI
- Throws:
URIException- If the URI cannot be created.- See Also:
-
setURI
Deprecated.Sets the URI for this method.- Specified by:
setURIin interfaceHttpMethod- Parameters:
uri- URI to be set- Throws:
URIException- if a URI cannot be set- Since:
- 3.0
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects) Deprecated.Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)- Specified by:
setFollowRedirectsin interfaceHttpMethod- Parameters:
followRedirects- true if the method will automatically follow redirects, false otherwise.
-
getFollowRedirects
public boolean getFollowRedirects()Deprecated.Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.- Specified by:
getFollowRedirectsin interfaceHttpMethod- Returns:
- true if the method will automatically follow HTTP redirects, false otherwise.
-
setHttp11
public void setHttp11(boolean http11) Deprecated.Sets whether version 1.1 of the HTTP protocol should be used per default.- Parameters:
http11- true to use HTTP/1.1, false to use 1.0
-
getDoAuthentication
public boolean getDoAuthentication()Deprecated.Returns true if the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.), false otherwise- Specified by:
getDoAuthenticationin interfaceHttpMethod- Returns:
- true if authentication challenges will be processed automatically, false otherwise.
- Since:
- 2.0
- See Also:
-
setDoAuthentication
public void setDoAuthentication(boolean doAuthentication) Deprecated.Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.)- Specified by:
setDoAuthenticationin interfaceHttpMethod- Parameters:
doAuthentication- true to process authentication challenges authomatically, false otherwise.- Since:
- 2.0
- See Also:
-
isHttp11
public boolean isHttp11()Deprecated.Returns true if version 1.1 of the HTTP protocol should be used per default, false if version 1.0 should be used.- Returns:
- true to use HTTP/1.1, false to use 1.0
-
setPath
Deprecated.Sets the path of the HTTP method. It is responsibility of the caller to ensure that the path is properly encoded (URL safe).- Specified by:
setPathin interfaceHttpMethod- Parameters:
path- the path of the HTTP method. The path is expected to be URL-encoded
-
addRequestHeader
Deprecated.Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.- Specified by:
addRequestHeaderin interfaceHttpMethod- Parameters:
header- the header to add to the request- See Also:
-
getPath
Deprecated.Gets the path of this HTTP method. Calling this method after the request has been executed will return the actual path, following any redirects automatically handled by this HTTP method.- Specified by:
getPathin interfaceHttpMethod- Returns:
- the path to request or "/" if the path is blank.
-
setQueryString
Deprecated.Sets the query string of this HTTP method. The caller must ensure that the string is properly URL encoded. The query string should not start with the question mark character.- Specified by:
setQueryStringin interfaceHttpMethod- Parameters:
queryString- the query string- See Also:
-
setQueryString
Deprecated.Sets the query string of this HTTP method. The pairs are encoded as UTF-8 characters. To use a different charset the parameters can be encoded manually using EncodingUtil and set as a single String.- Specified by:
setQueryStringin interfaceHttpMethod- Parameters:
params- an array ofNameValuePairs to add as query string parameters. The name/value pairs will be automcatically URL encoded- See Also:
-
getQueryString
Deprecated.Gets the query string of this HTTP method.- Specified by:
getQueryStringin interfaceHttpMethod- Returns:
- The query string
- See Also:
-
setRequestHeader
Deprecated.Set the specified request header, overwriting any previous value. Note that header-name matching is case-insensitive.- Specified by:
setRequestHeaderin interfaceHttpMethod- Parameters:
headerName- the header's nameheaderValue- the header's value- See Also:
-
setRequestHeader
Deprecated.Sets the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.- Specified by:
setRequestHeaderin interfaceHttpMethod- Parameters:
header- the header- See Also:
-
getRequestHeader
Deprecated.Returns the specified request header. Note that header-name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.- Specified by:
getRequestHeaderin interfaceHttpMethod- Parameters:
headerName- The name of the header to be returned.- Returns:
- The specified request header.
- Since:
- 3.0
-
getRequestHeaders
Deprecated.Returns an array of the requests headers that the HTTP method currently has- Specified by:
getRequestHeadersin interfaceHttpMethod- Returns:
- an array of my request headers.
- See Also:
-
getRequestHeaders
Deprecated.Description copied from interface:HttpMethodReturns the request headers with the given name. Note that header-name matching is case insensitive.- Specified by:
getRequestHeadersin interfaceHttpMethod- Parameters:
headerName- the name of the headers to be returned.- Returns:
- an array of zero or more headers
- See Also:
-
getResponseHeaders
Deprecated.Description copied from interface:HttpMethodReturns the response headers with the given name. Note that header-name matching is case insensitive.- Specified by:
getResponseHeadersin interfaceHttpMethod- Parameters:
headerName- the name of the headers to be returned.- Returns:
- an array of zero or more headers
- Since:
- 3.0
- See Also:
-
getStatusCode
public int getStatusCode()Deprecated.Returns the response status code.- Specified by:
getStatusCodein interfaceHttpMethod- Returns:
- the status code associated with the latest response.
-
getStatusLine
Deprecated.Provides access to the response status line.- Specified by:
getStatusLinein interfaceHttpMethod- Returns:
- the status line object from the latest response.
- Since:
- 2.0
-
getResponseHeaders
Deprecated.Returns an array of the response headers that the HTTP method currently has in the order in which they were read.- Specified by:
getResponseHeadersin interfaceHttpMethod- Returns:
- an array of response headers.
-
getResponseHeader
Deprecated.Gets the response header associated with the given name. Header name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.- Specified by:
getResponseHeaderin interfaceHttpMethod- Parameters:
headerName- the header name to match- Returns:
- the matching header
-
getResponseContentLength
public long getResponseContentLength()Deprecated.Return the length (in bytes) of the response body, as specified in a Content-Length header.Return -1 when the content-length is unknown.
- Returns:
- content length, if Content-Length header is available. 0 indicates that the request has no body. If Content-Length header is not present, the method returns -1.
-
getResponseBody
Deprecated.Returns the response body of the HTTP method, if any, as an array of bytes. If response body is not available or cannot be read, returns null. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.- Specified by:
getResponseBodyin interfaceHttpMethod- Returns:
- The response body.
- Throws:
IOException- If an I/O (transport) problem occurs while obtaining the response body.
-
getResponseBody
Deprecated.Returns the response body of the HTTP method, if any, as an array of bytes. If response body is not available or cannot be read, returns null. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. This method is safe if the content length of the response is unknown, because the amount of memory used is limited.If the response is large this method involves lots of array copying and many object allocations, which makes it unsuitable for high-performance / low-footprint applications. Those applications should use
getResponseBodyAsStream().- Parameters:
maxlen- the maximum content length to accept (number of bytes).- Returns:
- The response body.
- Throws:
IOException- If an I/O (transport) problem occurs while obtaining the response body.
-
getResponseBodyAsStream
Deprecated.Returns the response body of the HTTP method, if any, as anInputStream. If response body is not available, returns null. If the response has been buffered this method returns a new stream object on every call. If the response has not been buffered the returned stream can only be read once.- Specified by:
getResponseBodyAsStreamin interfaceHttpMethod- Returns:
- The response body or
null. - Throws:
IOException- If an I/O (transport) problem occurs while obtaining the response body.
-
getResponseBodyAsString
Deprecated.Returns the response body of the HTTP method, if any, as aString. If response body is not available or cannot be read, returns null The string conversion on the data is done using the character encoding specified in Content-Type header. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.- Specified by:
getResponseBodyAsStringin interfaceHttpMethod- Returns:
- The response body or
null. - Throws:
IOException- If an I/O (transport) problem occurs while obtaining the response body.
-
getResponseBodyAsString
Deprecated.Returns the response body of the HTTP method, if any, as aString. If response body is not available or cannot be read, returns null The string conversion on the data is done using the character encoding specified in Content-Type header. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. This method is safe if the content length of the response is unknown, because the amount of memory used is limited.If the response is large this method involves lots of array copying and many object allocations, which makes it unsuitable for high-performance / low-footprint applications. Those applications should use
getResponseBodyAsStream().- Parameters:
maxlen- the maximum content length to accept (number of bytes). Note that, depending on the encoding, this is not equal to the number of characters.- Returns:
- The response body or
null. - Throws:
IOException- If an I/O (transport) problem occurs while obtaining the response body.
-
getStatusText
Deprecated.Returns the status text (or "reason phrase") associated with the latest response.- Specified by:
getStatusTextin interfaceHttpMethod- Returns:
- The status text.
-
setStrictMode
public void setStrictMode(boolean strictMode) Deprecated.UseHttpParams.setParameter(String, Object)to exercise a more granular control over HTTP protocol strictness.Defines how strictly HttpClient follows the HTTP protocol specification (RFC 2616 and other relevant RFCs). In the strict mode HttpClient precisely implements the requirements of the specification, whereas in non-strict mode it attempts to mimic the exact behaviour of commonly used HTTP agents, which many HTTP servers expect.- Specified by:
setStrictModein interfaceHttpMethod- Parameters:
strictMode- true for strict mode, false otherwise- See Also:
-
isStrictMode
public boolean isStrictMode()Deprecated.UseHttpParams.setParameter(String, Object)to exercise a more granular control over HTTP protocol strictness.Description copied from interface:HttpMethodReturns the value of the strict mode flag.- Specified by:
isStrictModein interfaceHttpMethod- Returns:
- false
- See Also:
-
addRequestHeader
Deprecated.Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.- Specified by:
addRequestHeaderin interfaceHttpMethod- Parameters:
headerName- the header's nameheaderValue- the header's value- See Also:
-
execute
Deprecated.Executes this method using the specifiedHttpConnectionandHttpState.- Specified by:
executein interfaceHttpMethod- Parameters:
state-stateinformation to associate with this request. Must be non-null.conn- theconnectionto used to execute this HTTP method. Must be non-null.- Returns:
- the integer status code if one was obtained, or -1
- Throws:
IOException- if an I/O (transport) error occursHttpException- if a protocol exception occurs.
-
abort
public void abort()Deprecated.Aborts the execution of this method.- Specified by:
abortin interfaceHttpMethod- Since:
- 3.0
- See Also:
-
hasBeenUsed
public boolean hasBeenUsed()Deprecated.- Specified by:
hasBeenUsedin interfaceHttpMethod- Returns:
- true if the method has been executed, false otherwise
-
recycle
public void recycle()Deprecated.no longer supported and will be removed in the future version of HttpClientRecycles the HTTP method so that it can be used again. Note that all of the instance variables will be reset once this method has been called. This method will also release the connection being used by this HTTP method.- Specified by:
recyclein interfaceHttpMethod- See Also:
-
releaseConnection
public void releaseConnection()Deprecated.Releases the connection being used by this HTTP method. In particular the connection is used to read the response(if there is one) and will be held until the response has been read. If the connection can be reused by other HTTP methods it is NOT closed at this point.- Specified by:
releaseConnectionin interfaceHttpMethod- Since:
- 2.0
-
removeRequestHeader
Deprecated.Remove the request header associated with the given name. Note that header-name matching is case insensitive.- Specified by:
removeRequestHeaderin interfaceHttpMethod- Parameters:
headerName- the header name
-
removeRequestHeader
Deprecated.Removes the given request header.- Specified by:
removeRequestHeaderin interfaceHttpMethod- Parameters:
header- the header
-
validate
public boolean validate()Deprecated.Returns true the method is ready to execute, false otherwise.- Specified by:
validatein interfaceHttpMethod- Returns:
- This implementation always returns true.
-
getParams
Deprecated.ReturnsHTTP protocol parametersassociated with this method.- Specified by:
getParamsin interfaceHttpMethod- Returns:
- HTTP parameters.
- Since:
- 3.0
- See Also:
-
setParams
Deprecated.AssignsHTTP protocol parametersfor this method.- Specified by:
setParamsin interfaceHttpMethod- Since:
- 3.0
- See Also:
-
getEffectiveVersion
Deprecated.Returns the HTTP version used with this method (may be null if undefined, that is, the method has not been executed)- Returns:
- HTTP version.
- Since:
- 3.0
-
getProxyAuthenticationRealm
Deprecated.use #getProxyAuthState()Returns proxy authentication realm, if it has been used during authentication process. Otherwise returns null.- Returns:
- proxy authentication realm
-
getAuthenticationRealm
Deprecated.use #getHostAuthState()Returns authentication realm, if it has been used during authentication process. Otherwise returns null.- Returns:
- authentication realm
-
getRequestCharSet
Deprecated.Returns the character encoding of the request from the Content-Type header.- Returns:
- String The character set.
-
getResponseCharSet
Deprecated.Returns the character encoding of the response from the Content-Type header.- Returns:
- String The character set.
-
getRecoverableExceptionCount
public int getRecoverableExceptionCount()Deprecated.no longer used Returns the number of "recoverable" exceptions thrown and handled, to allow for monitoring the quality of the connection.- Returns:
- The number of recoverable exceptions handled by the method.
-
getHostConfiguration
Deprecated.no longer applicableReturns thehost configuration.- Specified by:
getHostConfigurationin interfaceHttpMethod- Returns:
- the host configuration
-
setHostConfiguration
Deprecated.no longer applicableSets thehost configuration.- Parameters:
hostconfig- The hostConfiguration to set
-
getMethodRetryHandler
Deprecated.useHttpMethodParamsReturns theretry handlerfor this HTTP method- Returns:
- the methodRetryHandler
-
setMethodRetryHandler
Deprecated.useHttpMethodParamsSets theretry handlerfor this HTTP method- Parameters:
handler- the methodRetryHandler to use when this method executed
-
getHostAuthState
Deprecated.Returns the target hostauthentication state- Specified by:
getHostAuthStatein interfaceHttpMethod- Returns:
- host authentication state
- Since:
- 3.0
-
getProxyAuthState
Deprecated.Returns the proxyauthentication state- Specified by:
getProxyAuthStatein interfaceHttpMethod- Returns:
- host authentication state
- Since:
- 3.0
-
isAborted
public boolean isAborted()Deprecated.Tests whether the execution of this method has been aborted- Returns:
- true if the execution of this method has been aborted, false otherwise
- Since:
- 3.0
-
isRequestSent
public boolean isRequestSent()Deprecated.Returns true if the HTTP has been transmitted to the target server in its entirety, false otherwise. This flag can be useful for recovery logic. If the request has not been transmitted in its entirety, it is safe to retry the failed method.- Specified by:
isRequestSentin interfaceHttpMethod- Returns:
- true if the request has been sent, false otherwise
-