pub struct Response { /* private fields */ }Expand description
HTTP 响应
Implementations§
Source§impl Response
impl Response
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
检查响应是否成功 (2xx)
Sourcepub fn is_informational(&self) -> bool
pub fn is_informational(&self) -> bool
检查是否为信息响应 (1xx)
Sourcepub fn is_redirection(&self) -> bool
pub fn is_redirection(&self) -> bool
检查是否为重定向 (3xx)
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
检查是否为客户端错误 (4xx)
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
检查是否为服务器错误 (5xx)
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
获取 Content-Type
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
获取 Content-Length
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
消费响应,获取响应体字节
Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T, HttpError>
pub fn json<T: DeserializeOwned>(&self) -> Result<T, HttpError>
将响应体解析为 JSON
Sourcepub fn into_json<T: DeserializeOwned>(self) -> Result<T, HttpError>
pub fn into_json<T: DeserializeOwned>(self) -> Result<T, HttpError>
消费响应,将响应体解析为 JSON
Sourcepub fn error_for_status(self) -> Result<Self, HttpError>
pub fn error_for_status(self) -> Result<Self, HttpError>
确保响应成功,否则返回错误
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more