|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface HttpMethod
HttpMethod interface represents a request to be sent via a
HTTP connection
and a corresponding response.
Method Summary | |
---|---|
void |
abort()
Aborts the execution of the HTTP method. |
void |
addRequestHeader(Collection<Header> headers)
Adds the specified request headers, not overwriting any previous value. |
void |
addRequestHeader(Header header)
Adds the specified request header, not overwriting any previous value. |
void |
addRequestHeader(String headerName,
String headerValue)
Adds the specified request header, not overwriting any previous value. |
void |
addResponseFooter(Header footer)
Add a footer to this method's response. |
int |
execute(HttpState state,
HttpConnection connection)
Executes this method using the specified HttpConnection and
HttpState . |
boolean |
getDoAuthentication()
Returns true if the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.), false otherwise |
boolean |
getFollowRedirects()
Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise. |
AuthState |
getHostAuthState()
Returns the target host authentication state |
String |
getName()
Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST". |
HttpMethodParams |
getParams()
Returns HTTP protocol parameters associated with this method. |
String |
getPath()
Returns the path of the HTTP method. |
AuthState |
getProxyAuthState()
Returns the proxy authentication state |
String |
getQueryString()
Returns the query string of this HTTP method. |
Header |
getRequestHeader(String headerName)
Gets the request header with the given name. |
Header[] |
getRequestHeaders()
Returns the current request headers for this HTTP method. |
Header[] |
getRequestHeaders(String headerName)
Returns the request headers with the given name. |
byte[] |
getResponseBody()
Returns the response body of the HTTP method, if any, as an array of bytes. |
InputStream |
getResponseBodyAsStream()
Returns the response body of the HTTP method, if any, as an InputStream. |
String |
getResponseBodyAsString()
Returns the response body of the HTTP method, if any, as a String . |
Header |
getResponseFooter(String footerName)
Return the specified response footer. |
Header[] |
getResponseFooters()
Returns the response footers from the most recent execution of this request. |
Header |
getResponseHeader(String headerName)
Returns the specified response header. |
Header[] |
getResponseHeaders()
Returns the response headers from the most recent execution of this request. |
Header[] |
getResponseHeaders(String headerName)
Returns the response headers with the given name. |
int |
getStatusCode()
Returns the status code associated with the latest response. |
StatusLine |
getStatusLine()
Returns the Status-Line from the most recent response for this method, or null if the method has not been executed. |
String |
getStatusText()
Returns the status text (or "reason phrase") associated with the latest response. |
URI |
getURI()
Returns the URI for this method. |
boolean |
hasBeenUsed()
Returns true if the HTTP method has been already executed . |
boolean |
isRequestSent()
Returns true if the HTTP has been transmitted to the target server in its entirety, false otherwise. |
void |
releaseConnection()
Releases the connection being used by this HTTP method. |
void |
removeRequestHeader(Header header)
Removes the given request header. |
void |
removeRequestHeader(String headerName)
Removes all request headers with the given name. |
void |
setDoAuthentication(boolean doAuthentication)
Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.) |
void |
setFilters(HttpConnection conn)
Give a method the opportunity to setup input and out filters on the given connection, so that they get activated on the next open() call of the connection. |
void |
setFollowRedirects(boolean followRedirects)
Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.) |
void |
setLogWire(WireLog wire)
Set the wire used to log headers and bodies. |
void |
setParams(HttpMethodParams params)
Assigns HTTP protocol parameters for this method. |
void |
setPath(String path)
Sets the path of the HTTP method. |
void |
setQueryString(NameValuePair[] params)
Sets the query string of this HTTP method. |
void |
setQueryString(String queryString)
Sets the query string of the HTTP method. |
void |
setRequestHeader(Header header)
Sets the specified request header, overwriting any previous value. |
void |
setRequestHeader(String headerName,
String headerValue)
Sets the specified request header, overwriting any previous value. |
void |
setURI(URI uri)
Sets the URI for this method. |
boolean |
validate()
Returns true the method is ready to execute, false otherwise. |
Method Detail |
---|
String getName()
void setPath(String path)
path
- The path of the HTTP method. The path is expected
to be URL encoded.String getPath()
URI getURI() throws URIException
URIException
- if a URI cannot be constructedvoid setURI(URI uri) throws URIException
uri
- URI to be set
URIException
- if a URI cannot be setvoid setRequestHeader(String headerName, String headerValue)
headerName
- the header's nameheaderValue
- the header's valuesetRequestHeader(Header)
,
getRequestHeader(String)
,
removeRequestHeader(String)
void setRequestHeader(Header header)
header
- the header to be setsetRequestHeader(String,String)
,
getRequestHeader(String)
,
removeRequestHeader(String)
void addRequestHeader(String headerName, String headerValue)
headerName
- the header's nameheaderValue
- the header's valueaddRequestHeader(Header)
,
getRequestHeader(String)
,
removeRequestHeader(String)
void addRequestHeader(Header header)
header
- the headeraddRequestHeader(String,String)
,
getRequestHeader(String)
,
removeRequestHeader(String)
void addRequestHeader(Collection<Header> headers)
headers
- the header to addaddRequestHeader(String,String)
,
getRequestHeader(String)
,
removeRequestHeader(String)
Header getRequestHeader(String headerName)
headerName
- the header name
void removeRequestHeader(String headerName)
headerName
- the header namevoid removeRequestHeader(Header header)
header
- the headerboolean getFollowRedirects()
void setFollowRedirects(boolean followRedirects)
followRedirects
- true if the method will automatically follow redirects,
false otherwise.void setQueryString(String queryString)
queryString
- the query to be used in the request, with no leading '?' charactergetQueryString()
,
setQueryString(NameValuePair[])
void setQueryString(NameValuePair[] params)
params
- An array of NameValuePair
s to use as the query string.
The name/value pairs will be automatically URL encoded and should not
have been encoded previously.getQueryString()
,
setQueryString(String)
,
EncodingUtil.formUrlEncode(NameValuePair[], String)
String getQueryString()
setQueryString(NameValuePair[])
,
setQueryString(String)
Header[] getRequestHeaders()
addRequestHeader
.
If there are multiple request headers with the same name (e.g. Cookie
),
they will be returned as multiple entries in the array.
addRequestHeader(Header)
,
addRequestHeader(String,String)
Header[] getRequestHeaders(String headerName)
headerName
- the name of the headers to be returned.
boolean validate()
int getStatusCode()
String getStatusText()
Header[] getResponseHeaders()
Header getResponseHeader(String headerName)
headerName
- The name of the header to be returned.
Header[] getResponseHeaders(String headerName)
headerName
- the name of the headers to be returned.
Header[] getResponseFooters()
Header getResponseFooter(String footerName)
footerName
- The name of the footer.
byte[] getResponseBody() throws IOException
null
is returned. Note that this method does not propagate I/O exceptions.
If an error occurs while reading the body, null
will be returned.
null
if the
body is not available.
IOException
- if an I/O (transport) problem occursString getResponseBodyAsString() throws IOException
String
.
If response body is not available or cannot be read, null is returned.
The raw bytes in the body are converted to a String
using the
character encoding specified in the response's Content-Type header, or
ISO-8859-1 if the response did not specify a character set.
Note that this method does not propagate I/O exceptions.
If an error occurs while reading the body, null
will be returned.
String
, or null
if the body is not available.
IOException
- if an I/O (transport) problem occursInputStream getResponseBodyAsStream() throws IOException
null
is returned. Additionally, null
may be returned
if releaseConnection()
has been called or
if this method was called previously and the resulting stream was closed.
null
if it is not available
IOException
- if an I/O (transport) problem occursboolean hasBeenUsed()
executed
.
int execute(HttpState state, HttpConnection connection) throws HttpException, IOException
HttpConnection
and
HttpState
.
state
- the state
information to associate with this methodconnection
- the connection
used to execute
this HTTP method
IOException
- If an I/O (transport) error occurs. Some transport exceptions
can be recovered from.
HttpException
- If a protocol exception occurs. Usually protocol exceptions
cannot be recovered from.void abort()
execute(HttpState, HttpConnection)
void releaseConnection()
After this method is called, getResponseBodyAsStream()
will return
null
, and getResponseBody()
and getResponseBodyAsString()
may return null
.
void addResponseFooter(Header footer)
Note: This method is for internal use only and should not be called by external clients.
footer
- the footer to addStatusLine getStatusLine()
null
if the method has not been executed.
null
if the method has not been executedboolean getDoAuthentication()
setDoAuthentication(boolean)
void setDoAuthentication(boolean doAuthentication)
doAuthentication
- true to process authentication challenges
automatically, false otherwise.getDoAuthentication()
HttpMethodParams getParams()
HTTP protocol parameters
associated with this method.
HttpMethodParams
void setParams(HttpMethodParams params)
HTTP protocol parameters
for this method.
params
- parameters to set.HttpMethodParams
AuthState getHostAuthState()
authentication state
AuthState getProxyAuthState()
authentication state
boolean isRequestSent()
void setFilters(HttpConnection conn)
conn
- void setLogWire(WireLog wire)
wire
- null
to disable logging, the wire otherwise.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |