use reqwest::header::{HeaderMap, HeaderName, HeaderValue, CONTENT_TYPE};
pub use reqwest::Error as HttpError;
pub use reqwest::StatusCode;
use std::io::Read;
use std::result;
#[derive(Debug)]
pub struct Response {
pub status: StatusCode,
pub body: String,
}
pub fn get(url: &str) -> Result<Response> {
let mut res = reqwest::get(url).unwrap();
let mut body = String::new();
res.read_to_string(&mut body).unwrap();
let status = res.status();
Ok(Response { status, body })
}
pub fn soap_action(url: &str, action: &str, xml: &str) -> Result<Response> {
let soap_action = HeaderName::from_bytes(b"SOAPAction").unwrap();
let soap_value = HeaderValue::from_str(action).unwrap();
let mut hmap = HeaderMap::new();
hmap.insert(CONTENT_TYPE, "text/xml; charset=utf-8".parse().unwrap());
hmap.insert(soap_action, soap_value);
let client = reqwest::Client::new();
let mut response = client
.post(url)
.headers(hmap)
.body(xml.to_string())
.send()
.unwrap();
let mut body = String::new();
response.read_to_string(&mut body).unwrap();
let status = response.status();
Ok(Response { status, body })
}
pub type Result<T> = result::Result<T, HttpError>;