### Perform HTTP GET Request Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Example of initializing a request and executing a GET call with the updated API. ```text let mut req = ScReq::new(); let url = "https://www.baidu.com/"; let resp = req.get(url, None).unwrap(); // None = no extra headers/options println!("{}", resp.header()); ``` -------------------------------- ### Perform a GET Request Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Execute a GET request and access the response headers, body, and JSON content. ```rust use reqrio::*; fn main() { let mut req = ScReq::new(); let mut res = req.get("https://www.baidu.com", None).unwrap(); let header = res.header(); let body = res.decode_body().unwrap(); let json = res.json().unwrap(); } ``` -------------------------------- ### Get and set JSON values by XPath Source: https://github.com/xllgl2017/reqrio/blob/main/json/README.md Shows how to modify and retrieve nested JSON values using XPath-like syntax. ```rust fn get_set_value(){ let mut data=json::object!{"code": 0, "msg": "success", "data":[{"entityId": 1116288, "skuBatchProperty": 2}]}; data.set_value_by_xpath(".data.[0].entityId", 123).unwrap(); data.get_value_by_xpath(".data.[1].skuBatchProperty").unwrap(); } ``` -------------------------------- ### Initialize a Session Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Create and configure a new ScReq session with custom headers, ALPN, and timeouts. ```rust use reqrio::*; fn main() { let headers = json::object! { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding": "gzip, deflate, br, zstd", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", "Cache-Control": "no-cache", "Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0", "sec-ch-ua": r#""Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24""#, "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": r#""Windows""# }; let mut req = ScReq::new() .with_alpn(ALPN::Http20) .with_header_json(headers).unwrap() .with_timeout(Timeout::new_same(3000, 3)); } ``` -------------------------------- ### Open and interact with a WebSocket Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Demonstrates establishing a connection to a WebSocket server, sending a text frame, and reading the response. ```rust use reqrio::*; fn main() { let mut ws = WebSocket::open("wss://echo.websocket.org").unwrap(); ws.write_frame(WsFrame::new_text(true, "Hello")).unwrap(); let frame = ws.read_frame().unwrap(); println!("Received: {:?}", frame); } ``` -------------------------------- ### Issue a Certificate in Rust Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Shows how to configure a root signer, set subject details, add extensions, and sign a certificate. ```rust fn dd() { let mut ca_signer = CertSigner::root_siger(2048).unwrap(); ca_signer.set_expire(10).unwrap(); //Country code, only two characters ca_signer.add_subject(DnType::Country, "XX").unwrap(); ca_signer.add_subject(DnType::StateOrProvince, "XXX").unwrap(); ca_signer.add_subject(DnType::Locality, "XXX").unwrap(); ca_signer.add_subject(DnType::Organization, "XXX").unwrap(); ca_signer.add_subject(DnType::OrganizationalUnit, "XXX").unwrap(); ca_signer.add_subject(DnType::Common, "XXX").unwrap(); //Certificate Purpose ca_signer.add_extension(CertExtend::KeyUsage(vec![KeyUsage::Critical, KeyUsage::KeyCertSign, KeyUsage::CrlSign])).unwrap(); ca_signer.add_extension(CertExtend::KeyIdentifier(vec![KeyIdentifier::Hash])).unwrap(); ca_signer.add_extension(CertExtend::BasicConstraints(vec![BasicConstraint::Critical, BasicConstraint::Ca(true)])).unwrap(); ca_signer.sign_by_self().unwrap(); fs::write("ca.der", ca_signer.cert.as_der().as_slice()).unwrap(); } ``` -------------------------------- ### Create JSON objects and arrays Source: https://github.com/xllgl2017/reqrio/blob/main/json/README.md Demonstrates the initialization of JSON objects and arrays using the object! and array! macros. ```rust fn main() { let object = object! { "foo": 42, "bar": false, }; let array = array![ { "foo": 42, "bar": fase } ]; } ``` -------------------------------- ### Read and Write Certificates in Rust Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Demonstrates loading certificate chains and private keys from PEM files and writing them to DER format. ```rust use std::fs; fn dd() { //Read certificate chain let certificates = Certificate::from_pem_file(pem)?; //Read certificate private key let certificate_key = RsaKey::from_pri_pem_file(key)?; //Certificate writing fs::write("1.der", certificates[0].as_der().as_slice()).unwrap(); } ``` -------------------------------- ### RSA Key Generation and Encryption in Rust Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Demonstrates generating RSA keys, exporting to PEM/DER, and performing encryption/decryption operations. ```rust fn dd() { let key = RsaKey::gen_new_key(2048).unwrap(); println!("{}", key.to_pri_pem().unwrap()); println!("{}", key.to_pub_pem().unwrap()); println!("{:?}", key.to_pri_der()); println!("{:?}", key.to_pub_der()); let nkey = RsaKey::from_pub_der(key.to_pub_der()).unwrap(); let rsa = RsaCipher::from_key(nkey).unwrap(); let encrypted = rsa.encrypt("adsdfds", true).unwrap(); println!("{} {:?}", encrypted.len(), encrypted); let nkey = RsaKey::from_pri_der(key.to_pri_der()).unwrap(); let rsa = RsaCipher::from_key(nkey).unwrap(); let decrypted = rsa.decrypt(encrypted.as_slice(), true).unwrap(); println!("{} {:?}", decrypted.len(), decrypted); } ``` -------------------------------- ### Configure Custom ClientHello Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Construct a custom TLS fingerprint from a decoded hex ClientHello string. ```rust let client_hello = hex_decode(fingerprint["tls_finger"].to_string()) ?; req.set_fingerprint(Fingerprint::from_client_hello(client_hello, "")) ?; ``` -------------------------------- ### Update Request Interface Usage Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Demonstrates the migration from the v0.2.0 request pattern to the simplified v0.3.0 interface. ```text // Before (v0.2.0) // let req = ScReq::new(); // req.set_url(url).unwrap(); // let resp=req.get().unwrap(); // After (v0.3.0) let mut req = ScReq::new(); let resp = req.get(url, None)?; // 2nd arg = optional headers/options (None to skip) ``` -------------------------------- ### Hashing and HMAC Usage in Rust Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Shows how to use the Hasher API for MD5 and HMAC operations. ```rust fn dd() { let mut hasher = Hasher::new(HashType::MD5).unwrap(); hasher.update("dfsdf").unwrap(); let md5 = hasher.finalize().unwrap(); let md5 = hash::md5("dfsdf").unwrap(); let md5_hex = hash::md5_hex("sdsdf").unwrap(); let mut hmac = Hmac::new("key", HashType::Sha256).unwrap(); hmac.update("fs").unwrap(); let bs = hmac.finalize().unwrap(); } ``` -------------------------------- ### Build record message Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Constructs a record message for transmission. ```text Connection::make_message(RecordType, out, int) ``` -------------------------------- ### Perform Cipher Encryption and Decryption in Rust Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Illustrates DES CBC encryption/decryption and convenient AES-based base64 encoding. ```rust fn dd() { let mut aes = Cipher::des_cbc(); aes.set_secret_key("12345678", Some("12345678")); let encrypted = aes.encrypt("1234567812345678jhjfhhhhhhhhhhhhhhdhhhhhhhgfdsfdsefdutrythdyrfgytyth8").unwrap(); println!("{:?}", encrypted); let b64 = base64::b64encode(encrypted).unwrap(); println!("encrypted: {}", b64); let de_bs = base64::b64decode(b64).unwrap(); println!("decrypted: {:?}", de_bs); println!("{:?}", aes.decrypt(de_bs).unwrap()); //Convenient AES based 64 encryption let res = cipher::en_b64(CipherType::AES_128_CBC, "1234567812345678", Some("1234567812345678"), "dada"); } ``` -------------------------------- ### Perform a POST Request with a Serialize Struct Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Send a serialized struct as a JSON body in a POST request, requiring the serde feature. ```rust use reqrio::*; use serde::Serialize; fn main() { #[derive(Serialize)] struct Data { field1: String, field2: bool, } let mut req = ScReq::new(); let url = "https://www.baidu.com/api"; let resp = req.post(url, Body::json(&Data { field1: "value".to_string(), field2: false }).unwrap()).unwrap(); } ``` -------------------------------- ### Configure Custom HTTP/2 Fingerprint Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Sets custom HTTP/2 parameters including settings, window size, and priority to control connection scheduling. ```text let h2 = H2Finger { setting: vec![ H2Setting::EnablePush(0), // 0 = disable server push H2Setting::HeaderTableSize(4096), H2Setting::InitialWindowSize(8192), H2Setting::MaxHeaderListSize(242144), ], window_size: 2147418112, weight: 234, // priority weight priority: true, // enable priority }; ``` -------------------------------- ### Perform a Form POST Request Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Send form-encoded data via a POST request. ```rust use reqrio::*; fn main() { let mut req = ScReq::new(); let url = "https://www.baidu.com/api"; let data = json::object! { "field1": "value1", "field2": "value2" }; let resp = req.post(url, data.form()).unwrap(); } ``` -------------------------------- ### Configure mTLS Client in Rust Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Enable mutual TLS by providing client certificate and private key paths to the ScReq instance. ```rust use reqrio::*; let mut req=ScReq::new(); let certs=Certificate::from_pem_file("path/to/cert").unwrap(); let key=RsaKey::from_pri_pem_file("path/to/cert/key").unwrap(); req.set_mtls(certs,key); ``` -------------------------------- ### Generate communication keys Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Generates keys after the client exchange key phase. ```text Connection::make_cipher(bool) ``` -------------------------------- ### Perform a JSON POST Request Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Send JSON data via a POST request. ```rust use reqrio::*; fn main() { let mut req = ScReq::new(); let url = "https://www.baidu.com/api"; let data = json::object! { "field1": "value1", "field2": "value2" }; let resp = req.post(url, data).unwrap(); } ``` -------------------------------- ### mTLS Configuration Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Configuring mutual TLS (mTLS) for the client by providing a certificate and private key. ```APIDOC ## mTLS Configuration ### Description Enables mutual TLS (mTLS) on the client side by configuring a client certificate and private key through `ClientConfig`. ### Example ```rust use reqrio::*; let mut req = ScReq::new(); let certs = Certificate::from_pem_file("path/to/cert").unwrap(); let key = RsaKey::from_pri_pem_file("path/to/cert/key").unwrap(); req.set_mtls(certs, key); ``` ``` -------------------------------- ### Set TLS Fingerprints Source: https://github.com/xllgl2017/reqrio/blob/main/reqrio/README.md Apply JA3 or JA4 fingerprints to a request using a token. ```rust req.set_ja3("", ""); req.set_ja4("", ""); ``` -------------------------------- ### Reqrio C Export Functions Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md A comprehensive list of C export functions available in Reqrio for handling HTTP requests and WebSocket communication. ```APIDOC ## Reqrio C Export Functions ### Description Reqrio provides a set of C export functions that can be invoked from various programming languages to perform HTTP and WebSocket operations. Users must manually manage instances to avoid memory leaks. ### Functions - **ScReq_new**() -> void * - **ScReq_set_header_json**(void *, const char *) -> int - **ScReq_add_header**(void *, const char *, const char *) -> int - **ScReq_set_alpn**(void *, const char *) -> int - **ScReq_set_random_fingerprint**(void *) -> int - **ScReq_set_fingerprint**(void *, const char *) -> int - **ScReq_set_ja3**(void *, const char *) -> int - **ScReq_set_ja4**(void *, const char *) -> int - **ScReq_set_proxy**(void *, const char *) -> int - **ScReq_set_url**(void *, const char *) -> int - **ScReq_add_param**(void *, const char *, const char *) -> int - **ScReq_set_data**(void *, const char *) -> int - **ScReq_set_json**(void *, const char *) -> int - **ScReq_set_bytes**(void *, const char *, uint32_t) -> int - **ScReq_set_text**(void *, const char *) -> int - **ScReq_set_timeout**(void *, const char *) -> int - **ScReq_set_cookie**(void *, const char *) -> int - **ScReq_add_cookie**(void *, const char *, const char *) -> int - **ScReq_set_callback**(void *, extern "C" fn(const char *, uint32_t)) -> int - **ScReq_reconnect**(void *) -> int - **ScReq_stream_io**(void *, Method) -> char * - **ScReq_drop**(void *) -> - - **char_free**(char *) -> - - **ws_build**() -> void * - **ws_add_header**(void *, const char *, const char *) -> int - **ws_set_proxy**(void *, const char *) -> int - **ws_set_url**(void *, const char *) -> int - **ws_set_uri**(void *, const char *) -> int - **ws_open**(void *) -> void * - **ws_open_raw**(const char *, const char *) -> void * - **ws_read**(void *) -> char * - **ws_write**(void *, int, bool, const char *) -> int - **ws_close**(void *) -> - ### Notes - Functions return -1 if unavailable. - Instances must be manually released to prevent memory leaks. ``` -------------------------------- ### Exported Functions Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Reference for the exported C-style functions for cryptographic operations. ```APIDOC ## Exported Functions ### Cipher Operations - **Cipher_new** (CipherType) -> void * - **Cipher_set_secret_key** (void *, const uint8_t *, size_t, const uint8_t *, size_t) -> int - **Cipher_encrypt** (void *, const uint8_t *, size_t, uint8_t **, size_t) -> int - **Cipher_decrypt** (void *, const uint8_t *, size_t, uint8_t **, size_t) -> int - **Cipher_free** (void *) -> void ### Hasher Operations - **Hasher_new** (HashType) -> void * - **Hasher_update** (void *, const uint8_t *, size_t) -> int - **Hasher_finalize** (void *, uint8_t **, size_t) -> int - **Hasher_free** (void *) -> void ### HMAC Operations - **Hmac_new** (uint8_t **, size_t, HashType) -> void * - **Hmac_update** (void *, const uint8_t *, size_t) -> int - **Hmac_finalize** (void *, uint8_t **, size_t) -> int - **Hmac_free** (void *) -> void ### Encoding/Decoding - **Base64_new** () -> void * - **Base64_encode** (void *, const uint8_t *, size_t) -> char * - **Base64_decode** (void *, const uint8_t *, size_t, uint8_t **, size_t) -> int - **Base64_free** (void *) -> void - **url_encode** (const char *) -> char * - **url_decode** (const char *) -> char * - **hex_encode** (const unt8_t, size_t) -> char * - **hex_decode** (const char *, uint8_t **, size_t) -> int ``` -------------------------------- ### Configure Custom TLS Fingerprint Source: https://github.com/xllgl2017/reqrio/blob/main/CHANGELOG.md Defines a custom TLS fingerprint by specifying cipher suites and extensions to simulate specific browser behavior. ```text let finger = TlsFinger::Custom { suites: vec![ CipherSuite::TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256.into(), CipherSuite::TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384.into(), CipherSuite::TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256.into(), CipherSuite::TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA.into(), CipherSuite::TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA.into(), CipherSuite::TLS_AES_128_GCM_SHA256.into(), CipherSuite::TLS_AES_256_GCM_SHA384.into(), CipherSuite::TLS_CHACHA20_POLY1305_SHA256.into(), ], extensions: vec![ ExtensionType::StatusRequest.into(), Extension::new(ExtensionType::SupportedGroup, ExtensionValue::Curves(vec![ NamedCurve::X25519.into(), NamedCurve::SecP256r1.into(), NamedCurve::SecP384r1.into(), NamedCurve::SecP521r1.into(), ])) ] } ``` -------------------------------- ### Read record message Source: https://github.com/xllgl2017/reqrio/blob/main/reqtls/README.md Reads a record message from the connection. ```text Connection::read_message(int,out) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.