I'd like to send an HTTPS request over UDP to a server on the internet (where I don't know if the server supports HTTPS over UDP). As a toy example, right now, I'm trying to send a GET request to http://httpbin.org/get. How do I do this?
Right now, I'm doing this in Rust, and my code looks like this:
use std::net::ToSocketAddrs;
fn main() {
let socket = std::net::UdpSocket::bind("127.0.0.1:34254").unwrap();
let remote_addr: std::net::SocketAddr = "httpbin.org:80".to_socket_addrs().unwrap().next().unwrap();
socket.connect(remote_addr).unwrap();
let msg = "GET /get HTTP/1.1\r\nHost: httpbin.org\r\naccept: application/json\r\n\r\n\r\n";
socket.send(msg.as_bytes()).unwrap();
let mut buf = [0; 5000];
let num_bytes = socket.recv(&mut buf).unwrap();
println!("recieved {} bytes: {:?}", num_bytes, std::str::from_utf8(&buf[..num_bytes]));
}
However, when I run the code I get the following output (this happens on socket.connect(...)):
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', ...
Is what I'm doing even possible? Or am I doing it wrong?