Struct lta::ureq_blocking::Agent
pub struct Agent { /* private fields */ }
Expand description
Agents keep state between requests.
By default, no state, such as cookies, is kept between requests. But by creating an agent as entry point for the request, we can keep a state.
let mut agent = ureq::agent();
agent
.post("http://example.com/post/login")
.call()?;
let secret = agent
.get("http://example.com/get/my-protected-page")
.call()?
.into_string()?;
println!("Secret is: {}", secret);
Agent uses an inner Arc, so cloning an Agent results in an instance that shares the same underlying connection pool and other state.
Implementations§
§impl Agent
impl Agent
pub fn request(&self, method: &str, path: &str) -> Request
pub fn request(&self, method: &str, path: &str) -> Request
Make a request with the HTTP verb as a parameter.
This allows making requests with verbs that don’t have a dedicated method.
If you’ve got an already-parsed Url, try request_url.
use ureq::Response;
let agent = ureq::agent();
let resp: Response = agent
.request("OPTIONS", "http://example.com/")
.call()?;
pub fn request_url(&self, method: &str, url: &Url) -> Request
pub fn request_url(&self, method: &str, url: &Url) -> Request
Make a request using an already-parsed Url.
This is useful if you’ve got a parsed Url from some other source, or if
you want to parse the URL and then modify it before making the request.
If you’d just like to pass a String or a &str
, try request.
use {url::Url, ureq::Response};
let agent = ureq::agent();
let mut url: Url = "http://example.com/some-page".parse()?;
url.set_path("/get/robots.txt");
let resp: Response = agent
.request_url("GET", &url)
.call()?;
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Agent
impl Send for Agent
impl Sync for Agent
impl Unpin for Agent
impl !UnwindSafe for Agent
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