seanmonstar / reqwest

An easy and powerful Rust HTTP Client
https://docs.rs/reqwest
Apache License 2.0
9.71k stars 1.09k forks source link

HandshakeFailure error #923

Open cinestria opened 4 years ago

cinestria commented 4 years ago

I tried website crawling with this codes

use std::collections::HashMap;
use reqwest::header::USER_AGENT;
use reqwest::header::ACCEPT;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    let res = client.post("https://opendart.fss.or.kr/api/list.json")
        .header(USER_AGENT, "test")
        .header(ACCEPT, "application/json")
        .send()
        .await?;
    println!("{:#?}", res);
    Ok(())
} 

but this codes returned error. Error: reqwest::Error { kind: Request, url: "https://opendart.fss.or.kr/api/list.json", source: hyper::Error(Connect, Custom { kind: Other, error: Custom { kind: InvalidData, error: AlertReceived(HandshakeFailure) } }) }

so then i tried another code with curl library

use std::io::{stdout, Write};

use curl::easy::Easy;
use curl::easy::List;

// Print a web page onto stdout
fn main() {
    let mut easy = Easy::new();
    let mut list = List::new();
    list.append("user-agent: test").unwrap();
    list.append("accept: application/json").unwrap();

    easy.url("https://opendart.fss.or.kr/api/list.json").unwrap();
    easy.http_headers(list).unwrap();

    easy.write_function(|data| {
        stdout().write_all(data).unwrap();
        println!("{}", data.len());
        Ok(data.len())
    }).unwrap();
    easy.perform().unwrap();    

    println!("{}", easy.response_code().unwrap());
}

this codes is fine.

I want to know why this is happening.

Darkspirit commented 4 years ago

https://www.hardenize.com/report/opendart.fss.or.kr/1590494615#www_tls This server is horribly configured and does not support modern encryption. Therefore many clients won't be able to connect. If you are using Rustls, it correctly demands the use of ECDHE ciphersuites - which this server does not offer.

cinestria commented 4 years ago

Thanks for your response.

In fact Korea's government sites are poor maintenance. 😂

Is there no other way than to use curl?

because i use deno lang. by the way deno use reqwest in internal deno code.