Hello there,
I'm very new to rust, i want to try this langage.
I want to do a curl post request but in my POST i send an xml (that i import with a file) to the apache tomcat server, which in return needs to give me back a response. For yet it does give me a response but i think it's because the Xml that i send it not encoded properly. I tried different methods to import it but everytime it says it doesn't have a proper read methods. So i tried to convert it with as_bytes but it gives me this error :
<!doctype html><html lang="fr"><head><title>État HTTP 500 – Erreur interne du serveur</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>État HTTP 500 – Erreur interne du serveur</h1><hr class="line" /><p><b>Type</b> Rapport d'état</p><p><b>message</b> Error executing job: Error reading log file: <?xml version="1.0"?>
<error component="XmlUtils" desc="XML parsing error. See Message for details."
here is my code :
let contents = fs::read_to_string(filename)
.expect("Something went wrong reading the file");
let mut contentsbyte = contents.as_bytes();
println!("With text:\n{}", contents);
let mut dataread = String::new();
let f = File::open(filename).expect("Unable to open file");
let mut br = BufReader::new(f);
br.read_to_string(&mut dataread).expect("Unable to read string");
println!("{}", dataread);
let mut datareadr = dataread.as_bytes();
let mut easy = Easy::new();
easy.url(lxmlsrv_url).unwrap();
easy.post(true).unwrap();
let mut transfer = easy.transfer();
transfer.read_function(|into| {
Ok(contentsbyte.read(into).unwrap())
}).unwrap();
transfer.write_function(|data| {
// "data!" is never printed
println!("data!");
stdout().flush().unwrap();
Ok(stdout().write(data).unwrap())
});
transfer.perform().unwrap();
```
>
> So, is there any methods/functions to send/import a file with the right encoding ? Thanks in advance !