Successful HTTP request

This commit is contained in:
Adam Cooper 2021-12-16 08:53:25 -05:00
parent bcd5090ebd
commit 57da34b095

View file

@ -16,8 +16,7 @@ use xml::reader::{EventReader, XmlEvent};
fn publicise() {
}
#[allow(unused)]
async fn get_folder_contents(password: String, url_tail: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>> {
async fn get_folder_contents(password: String, url_tail: &str) -> Result<String, Box<dyn std::error::Error>> {
debug!("Entering: get_folder_contents()");
let root_url = "https://theadamcooper.com";
let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap();
@ -36,13 +35,15 @@ async fn get_folder_contents(password: String, url_tail: &str) -> Result<reqwest
<oc:share-types/>
</d:prop>
</d:propfind>"#);
let response = client.request(method, url)
let response_text = client.request(method, url)
.basic_auth("adam", Some(password))
.body(body)
.send()
.await?
.text()
.await?;
debug!("{:?}", response);
Ok(response)
debug!("{:?}", response_text);
Ok(response_text)
}
fn get_password() -> Result<String, std::io::Error> {
@ -57,13 +58,13 @@ fn get_password() -> Result<String, std::io::Error> {
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("trace")).target(Target::Stdout).init();
println!("Publicise it!");
let password = get_password().unwrap();
debug!("Received password: {}", password);
let password = get_password().unwrap().trim().to_string();
debug!("Received password: {}[END]", password);
let folder_contents = get_folder_contents(password, "/nextcloud/remote.php/dav/files/adam/public").await?;
let folder_contents = get_folder_contents(password, "/nextcloud/remote.php/dav/files/adam/public").await;
debug!("{:?}", folder_contents);
Ok(())
}