|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
HttpMethod interface represents a request to be sent via a
HTTP connection
and a corresponding response.
Method Summary | |
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. |
HostConfiguration |
getHostConfiguration()
Gets the host configuration for this method. |
String |
getName()
Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST". |
String |
getPath()
Returns the path of the HTTP method. |
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. |
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. |
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 ,
but not recycled . |
boolean |
isStrictMode()
Returns the value of the strict mode flag. |
void |
recycle()
Deprecated. no longer supported and will be removed in the future version of HttpClient |
void |
releaseConnection()
Releases the connection being used by this HTTP method. |
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 |
setFollowRedirects(boolean followRedirects)
Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.) |
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 |
setStrictMode(boolean strictMode)
Defines how strictly the method follows the HTTP protocol specification. |
boolean |
validate()
Returns true the method is ready to execute, false otherwise. |
Method Detail |
public String getName()
public HostConfiguration getHostConfiguration()
null
if none is setpublic void setPath(String path)
path
- The path of the HTTP method. The path is expected
to be URL encoded.public String getPath()
public URI getURI() throws URIException
URIException
- if a URI cannot be constructedpublic void setStrictMode(boolean strictMode)
strictMode
- true for strict mode, false otherwiseisStrictMode()
public boolean isStrictMode()
setStrictMode(boolean)
public void setRequestHeader(String headerName, String headerValue)
headerName
- the header's nameheaderValue
- the header's valuesetRequestHeader(Header)
,
getRequestHeader(String)
,
removeRequestHeader(String)
public void setRequestHeader(Header header)
header
- the header to be setsetRequestHeader(String,String)
,
getRequestHeader(String)
,
removeRequestHeader(String)
public void addRequestHeader(String headerName, String headerValue)
headerName
- the header's nameheaderValue
- the header's valueaddRequestHeader(Header)
,
getRequestHeader(String)
,
removeRequestHeader(String)
public void addRequestHeader(Header header)
header
- the headeraddRequestHeader(String,String)
,
getRequestHeader(String)
,
removeRequestHeader(String)
public Header getRequestHeader(String headerName)
headerName
- the header namepublic void removeRequestHeader(String headerName)
headerName
- the header namepublic boolean getFollowRedirects()
public void setFollowRedirects(boolean followRedirects)
followRedirects
- true if the method will automatically follow redirects,
false otherwisepublic void setQueryString(String queryString)
queryString
- the query to be used in the request, with no leading '?' charactergetQueryString()
,
setQueryString(NameValuePair[])
public 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)
public String getQueryString()
setQueryString(NameValuePair[])
,
setQueryString(String)
public 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)
public boolean validate()
public int getStatusCode()
public String getStatusText()
public Header[] getResponseHeaders()
public Header getResponseHeader(String headerName)
headerName
- The name of the header to be returned.public Header[] getResponseFooters()
public Header getResponseFooter(String footerName)
footerName
- The name of the footer.public byte[] getResponseBody()
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.public String getResponseBodyAsString()
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.public InputStream 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 availableIOException
- if an I/O (transport) problem occurspublic boolean hasBeenUsed()
executed
,
but not recycled
.public 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 methodIOException
- 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.public void recycle()
releaseConnection()
public void releaseConnection()
After this method is called, getResponseBodyAsStream()
will return
null
, and getResponseBody()
and getResponseBodyAsString()
may return null
.
public void addResponseFooter(Header footer)
Note: This method is for internal use only and should not be called by external clients.
footer
- the footer to addpublic StatusLine getStatusLine()
null
if the method has not been executed.null
if the method has not been executedpublic boolean getDoAuthentication()
setDoAuthentication(boolean)
public void setDoAuthentication(boolean doAuthentication)
doAuthentication
- true to process authentication challenges
automatically, false otherwise.getDoAuthentication()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |