public final class CloseableHttpResponse extends Object implements ClassicHttpResponse
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addHeader(Header header)
Adds a header to this message.
|
void |
addHeader(String name,
Object value)
Adds a header to this message.
|
void |
close() |
boolean |
containsHeader(String name)
Checks if a certain header is present in this message.
|
int |
countHeaders(String name)
Checks if a certain header is present in this message and how many times.
|
int |
getCode()
Obtains the code of this response message.
|
HttpEntity |
getEntity()
Obtains the message entity, if available.
|
Header |
getFirstHeader(String name)
Returns the first header with a specified name of this message.
|
Header |
getHeader(String name)
Gets single first header with the given name.
|
Header[] |
getHeaders()
Returns all the headers of this message.
|
Header[] |
getHeaders(String name)
Returns all the headers with a specified name of this message.
|
Header |
getLastHeader(String name)
Returns the last header with a specified name of this message.
|
Locale |
getLocale()
Obtains the locale of this response.
|
String |
getReasonPhrase()
Obtains the reason phrase of this response if available.
|
ProtocolVersion |
getVersion()
Returns protocol version or
null when not available. |
Iterator<Header> |
headerIterator()
Returns an iterator of all the headers.
|
Iterator<Header> |
headerIterator(String name)
Returns an iterator of the headers with a given name.
|
boolean |
removeHeader(Header header)
Removes a header from this message.
|
boolean |
removeHeaders(String name)
Removes all headers with a certain name from this message.
|
void |
setCode(int code)
Updates status code of this response message.
|
void |
setEntity(HttpEntity entity)
Sets an entity for this message.
|
void |
setHeader(Header header)
Overwrites the first header with the same name.
|
void |
setHeader(String name,
Object value)
Overwrites the first header with the same name.
|
void |
setHeaders(Header... headers)
Overwrites all the headers in the message.
|
void |
setLocale(Locale loc)
Changes the locale of this response.
|
void |
setReasonPhrase(String reason)
Updates the status line of this response with a new reason phrase.
|
void |
setVersion(ProtocolVersion version)
Sets protocol version.
|
String |
toString() |
public int getCode()
HttpResponsegetCode 在接口中 HttpResponsepublic HttpEntity getEntity()
HttpEntityContainergetEntity 在接口中 HttpEntityContainernull if not availablepublic boolean containsHeader(String name)
MessageHeaderscontainsHeader 在接口中 MessageHeadersname - the header name to check for.public void setVersion(ProtocolVersion version)
HttpMessageFor incoming messages it represents protocol version this message was transmitted with. For outgoing messages it represents a hint what protocol version should be used to transmit the message.
setVersion 在接口中 HttpMessagepublic void setCode(int code)
HttpResponsesetCode 在接口中 HttpResponsecode - the HTTP status code.HttpStatuspublic String getReasonPhrase()
HttpResponsegetReasonPhrase 在接口中 HttpResponsepublic int countHeaders(String name)
MessageHeaderscountHeaders 在接口中 MessageHeadersname - the header name to check for.public void setEntity(HttpEntity entity)
HttpEntityContainerPlease note that if an entity has already been set it is responsibility of the caller to ensure release of the resources that may be associated with that entity.
setEntity 在接口中 HttpEntityContainerentity - the entity to set of this message, or null to unsetpublic ProtocolVersion getVersion()
HttpMessagenull when not available.
For incoming messages it represents protocol version this message was transmitted with. For outgoing messages it represents a hint what protocol version should be used to transmit the message.
getVersion 在接口中 HttpMessagepublic void setReasonPhrase(String reason)
HttpResponsesetReasonPhrase 在接口中 HttpResponsereason - the new reason phrase as a single-line string, or
null to unset the reason phrasepublic Header[] getHeaders(String name)
MessageHeadersgetHeaders 在接口中 MessageHeadersname - the name of the headers to return.name.public void addHeader(Header header)
HttpMessageaddHeader 在接口中 HttpMessageheader - the header to append.public Locale getLocale()
HttpResponsestatus code.
It can be changed using setLocale.getLocale 在接口中 HttpResponsenullpublic void addHeader(String name, Object value)
HttpMessageaddHeader 在接口中 HttpMessagename - the name of the header.value - the value of the header, taken as the value's Object.toString().public void setLocale(Locale loc)
HttpResponsesetLocale 在接口中 HttpResponseloc - the new localepublic Header getHeader(String name) throws ProtocolException
MessageHeadersHeader name comparison is case insensitive.
getHeader 在接口中 MessageHeadersname - the name of the header to getnullProtocolException - in case multiple headers with the given name are found.public void setHeader(Header header)
HttpMessagesetHeader 在接口中 HttpMessageheader - the header to set.public Header getFirstHeader(String name)
MessageHeadersMessageHeaders.getHeaders(String) is returned.
If there is no matching header in the message null is
returned.getFirstHeader 在接口中 MessageHeadersname - the name of the header to return.name
or null if no such header could be found.public void setHeader(String name, Object value)
HttpMessagesetHeader 在接口中 HttpMessagename - the name of the header.value - the value of the header, taken as the value's Object.toString().public void setHeaders(Header... headers)
HttpMessagesetHeaders 在接口中 HttpMessageheaders - the array of headers to set.public boolean removeHeader(Header header)
HttpMessageremoveHeader 在接口中 HttpMessageheader - the header to remove.true if a header was removed as a result of this call.public boolean removeHeaders(String name)
HttpMessageremoveHeaders 在接口中 HttpMessagename - The name of the headers to remove.true if any header was removed as a result of this call.public Header getLastHeader(String name)
MessageHeadersMessageHeaders.getHeaders(String) is returned. If there is no
matching header in the message null is returned.getLastHeader 在接口中 MessageHeadersname - the name of the header to return.name.
or null if no such header could be found.public Header[] getHeaders()
MessageHeadersgetHeaders 在接口中 MessageHeaderspublic Iterator<Header> headerIterator()
MessageHeadersheaderIterator 在接口中 MessageHeaderspublic Iterator<Header> headerIterator(String name)
MessageHeadersheaderIterator 在接口中 MessageHeadersname - the name of the headers over which to iterate, or
null for all headerspublic void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionCopyright © 2023. All rights reserved.