Hello;
I'm currently trying to make an HTTP request only using STD but all the resources I've found are outdated and 6 years old!
I don't understand why this is not working! This server uses Cloudflare and I get a 400 bad Request error.
(If I use a local server on Actix everything is fine)
fn req() -> std::io::Result<String> {
let host = "api.mcalts.fr:2082";
let path = "/v3/api/a/b/c";
let ip_lookup = host.to_socket_addrs()?.next().unwrap();
println!("{:?}", ip_lookup);
let mut socket = TcpStream::connect_timeout(&ip_lookup, Duration::from_millis(5000))?;
let mut headers = HashMap::new();
headers.insert("Host", host);
let mut header = format!("GET {} HTTP/1.1\n{}\n\n",path,headers.iter().map(|(i,x)| format!("{}: {}",i,x)).collect::<Vec<_>>().join("\n"));
println!("{}",header);
socket.write(header.as_bytes());
socket.flush();
let mut headers = String::new();
socket.read_to_string(&mut headers)?;
Ok(headers)
}
We should get OK 200 with invalid
as text but Cloudflare seems to be blocking the request for no apparent reason. (This request works from a Rest Client or Web Browser).
Thanks for your help;
ccgauche.