segunda-feira, 18 de maio de 2015

Make a dav call with Rust



extern crate hyper;


use std::io::Read;
use hyper::client::*;
use hyper::header::{Authorization, Basic};
use hyper::method::Method;

fn main() {
        let mut client = Client::new();
       
        // Create an directory
        let put = Method::Extension("MKCOL".to_owned());
        let mut res = client.request(put, "https://localhost:9898/webdav/test/")
            .header(Authorization(Basic { username: "webdav".to_string(), password: Some("123".to_string()) }))
            .send()
            .unwrap();       
       
       
        let put = Method::Extension("PUT".to_owned());
        let mut res = client.request(put, "https://localhost:9898/webdav/test/Validator.java")
            .body("foo=bar")
            .header(Authorization(Basic { username: "webdav".to_string(), password: Some("123".to_string()) }))
            .send()
            .unwrap();

        let mut body = String::new();
        res.read_to_string(&mut body).unwrap();

        println!("Response: {}", body);

}

Nenhum comentário:

Postar um comentário