[−][src]Struct ureq::Agent
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/login") .call()?; let secret = agent .get("http://example.com/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
[src]
pub fn new() -> Self
[src]
Creates an Agent with default settings.
Same as AgentBuilder::new().build()
.
pub fn request(&self, method: &str, path: &str) -> Request
[src]
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
[src]
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().unwrap(); url.set_path("/robots.txt"); let resp: Response = agent .request_url("GET", &url) .call()?;
pub fn get(&self, path: &str) -> Request
[src]
Make a GET request from this agent.
pub fn head(&self, path: &str) -> Request
[src]
Make a HEAD request from this agent.
pub fn post(&self, path: &str) -> Request
[src]
Make a POST request from this agent.
pub fn put(&self, path: &str) -> Request
[src]
Make a PUT request from this agent.
pub fn delete(&self, path: &str) -> Request
[src]
Make a DELETE request from this agent.
pub fn cookie_store(&self) -> CookieStoreGuard<'_>
[src]
Read access to the cookie store.
Used to persist the cookies to an external writer.
use std::io::Write; use std::fs::File; let agent = ureq::agent(); // Cookies set by www.google.com are stored in agent. agent.get("https://www.google.com/").call()?; // Saves (persistent) cookies let mut file = File::create("cookies.json")?; agent.cookie_store().save_json(&mut file).unwrap();
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Agent
[src]
impl Send for Agent
[src]
impl Sync for Agent
[src]
impl Unpin for Agent
[src]
impl !UnwindSafe for Agent
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,