Closed Decodetalkers closed 3 years ago
Like this . I have read the doc, but I still cannot handle it..
let mut res = surf::get(url).await?;
if res.status() != surf::StatusCode::Ok {
println!("Failed to download url");
}
let mut res = surf::get(url).await?; if res.status() != surf::StatusCode::Ok { println!("Failed to download url"); }
then how to return the surf::error, now my function return a surf::Result.
Thanks very much
let mut res = surf::get(url).await?; if res.status() != surf::StatusCode::Ok { println!("Failed to download url"); }
I tried, but it not help.
let mut res = surf::get(url).await?; if res.status() != surf::StatusCode::Ok { println!("Failed to download url"); }
Its my code
Then it panic at "await?", before handle the url
sss
is not a valid url. Surf requires a string that can be parsed into a Url
sss
is not a valid url. Surf requires a string that can be parsed into aUrl
This is what I need , I need to handle this error...,when people input a url or not url string, it will pop an error window
ahh. see the example at Request::new
:
use surf::http::{Url, Method};
let url = Url::parse("https://httpbin.org/get")?;
let req = surf::Request::new(Method::Get, url);
ahh. see the example at
Request::new
:use surf::http::{Url, Method}; let url = Url::parse("https://httpbin.org/get")?; let req = surf::Request::new(Method::Get, url);
It works, thanks