Http Get Request Failed

Hi, I'm trying to perform a Http Get Request but am encountering an error at Ok(mut response) and Err(_) => println!("Could not make the request!") saying it's expecting a std::future:Future but is getting an enum:result:Result. I'm not sure what future:Future is or what qualifies for it in the given context.

Thanks in advance.

fn get()
{
    match reqwest::get("http://localhost:8088")
    {
        Ok(mut response) =>
        {
            if response.status == reqwest::StatusCode::OK
            {
                match response.text()
                {
                    Ok(text) => println!("Response Text: {}", text),
                    Err(_) => println!("Could not read response text!")
                }
            }
            else
            {
                println!("Response was not 200 Ok.");
            }
        }
        Err(_) => println!("Could not make the request!")
    }
}

Since you are not writing an asynchronous application you should use the blocking module in reqwest.

match reqwest::blocking::get("http://localhost:8088") {
    ...
}

Thank you for your help, it works!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.