The message received was unexpected or badly formatted. #2411
-
Hi, I'm having an issue to contact my local webserver. It works well in HTTP but fails in HTTPS with this error:
I am able to contact my HTTPS server with other tools (web browser, CURL, Bruno, ...) without any issue. Here is my code: fn main() {
let client = Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap();
client.get("https://localhost:8443/hello").send().unwrap();
} The webserver is a TLS Axum with self signed certs with mkcert. I've also tried to add the root cert but the error stays the same: fn main() {
let pem = std::fs::read("C:\\Users\\[USER]\\AppData\\Local\\mkcert\\rootCA.pem").unwrap();
let cert = reqwest::Certificate::from_pem(&pem).unwrap();
let client = Client::builder()
.add_root_certificate(cert)
.danger_accept_invalid_certs(true)
.build()
.unwrap();
client.get("https://localhost:8443/hello").send().unwrap();
} Do you have any idea about the cause of this problem ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Have you tried looking up the error code? That number combined with "windows error" should likely bring up some solutions in search results. |
Beta Was this translation helpful? Give feedback.
-
@seanmonstar I didn't find any conclusive thing for this error on Windows. If I understand correctly it's a problem with the TLS handshake between the client/server.
I can make it work with rustls feature and the use_rustls_tls() in ClientBuilder. I don't really know what rustls is doing behind the scenes for this behaviour to happen. Thanks for the great library and have a good day ! |
Beta Was this translation helpful? Give feedback.
@seanmonstar I didn't find any conclusive thing for this error on Windows. If I understand correctly it's a problem with the TLS handshake between the client/server.
Knowing this, I looked at the features flags for the Reqwest crate and I tried different settings.
I can make it work with rustls feature and the use_rustls_tls() in ClientBuilder. I don't really know what rustls is doing behind the scenes for this behaviour to happen.
Thanks for the great library and have a good day !