pub struct HttpClient { /* private fields */ }Expand description
HTTP 客户端
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(config: HttpClientConfig) -> Self
pub fn new(config: HttpClientConfig) -> Self
创建新的 HTTP 客户端
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
使用默认配置创建
Sourcepub fn config(&self) -> &HttpClientConfig
pub fn config(&self) -> &HttpClientConfig
获取配置
Sourcepub async fn get(&self, url: &str) -> WaeResult<HttpResponse>
pub async fn get(&self, url: &str) -> WaeResult<HttpResponse>
发送 GET 请求
Sourcepub async fn get_with_headers(
&self,
url: &str,
headers: HashMap<String, String>,
) -> WaeResult<HttpResponse>
pub async fn get_with_headers( &self, url: &str, headers: HashMap<String, String>, ) -> WaeResult<HttpResponse>
发送带请求头的 GET 请求
Sourcepub async fn post_json<T: Serialize>(
&self,
url: &str,
body: &T,
) -> WaeResult<HttpResponse>
pub async fn post_json<T: Serialize>( &self, url: &str, body: &T, ) -> WaeResult<HttpResponse>
发送 POST JSON 请求
Sourcepub async fn post_with_headers(
&self,
url: &str,
body: Vec<u8>,
headers: HashMap<String, String>,
) -> WaeResult<HttpResponse>
pub async fn post_with_headers( &self, url: &str, body: Vec<u8>, headers: HashMap<String, String>, ) -> WaeResult<HttpResponse>
发送带请求头的 POST 请求
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HttpClient
impl Debug for HttpClient
Auto Trait Implementations§
impl Freeze for HttpClient
impl RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin for HttpClient
impl UnwindSafe for HttpClient
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