Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1834

I write the same statement as curl, but I am not getting any response - why?

$
0
0

I am trying to retrieve time from the Bybit exchange. Curl works as expected, but my code in Rust works only with HTTP/1.0, HTTP/1.1 is getting complete silence and HTTP/2 is getting an error from cloudfront.

I am using native-tls crate for TLS.

Curl:

curl --trace dump.txt --http1.1 -H 'User-Agent:' -H 'Accept:' https://api.bybit.com/v5/market/time

Rust:

use native_tls::TlsConnector;use std::io::{Read, Write};use std::net::TcpStream;const FROM_TRACE: [u8; 53] = [    // Offset 0x00000000 to 0x00000034    0x47, 0x45, 0x54, 0x20, 0x2F, 0x76, 0x35, 0x2F, 0x6D, 0x61, 0x72, 0x6B,    0x65, 0x74, 0x2F, 0x74, 0x69, 0x6D, 0x65, 0x20, 0x48, 0x54, 0x54, 0x50,    0x2F, 0x31, 0x2E, 0x31, 0x0D, 0x0A, 0x48, 0x6F, 0x73, 0x74, 0x3A, 0x20,    0x61, 0x70, 0x69, 0x2E, 0x62, 0x79, 0x62, 0x69, 0x74, 0x2E, 0x63, 0x6F,    0x6D, 0x0D, 0x0A, 0x0D, 0x0A];fn main() {    // Establish TCP connection    let stream = TcpStream::connect("api.bybit.com:443").unwrap();    // Create TlsConnector    let connector = TlsConnector::new().unwrap();    // Perform TLS handshake at TCP connection    let mut stream = connector.connect("api.bybit.com", stream).unwrap();    // Send request    let request = "GET /v5/market/time HTTP/1.1\r\nHost: api.bybit.com\r\n\r\n";    assert_eq!(request.as_bytes(), FROM_TRACE);    stream.write_all(&request.as_bytes()).unwrap();    // Get response    let mut res = vec![];    stream.read_to_end(&mut res).unwrap();    println!("{}", String::from_utf8_lossy(&res));}

Update: looks like @SteffenUllrich in commentary was right. I am shutting down TlsStream before reading it now, and it works as expected. I am confused, because I expected read (not read_to_end) to pull bytes independently of that.


Viewing all articles
Browse latest Browse all 1834

Latest Images

Trending Articles



Latest Images