tcvectordb 0.1.9

Rust SDK for Tencent Cloud VectorDB
Documentation
use reqwest::Client;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("🧪 Simple HTTP Test");
    
    let server_url = std::env::var("VECTORDB_URL")
        .unwrap_or_else(|_| "http://localhost:8100".to_string());
    let username = std::env::var("VECTORDB_USERNAME")
        .unwrap_or_else(|_| "root".to_string());
    let api_key = std::env::var("VECTORDB_API_KEY")
        .unwrap_or_else(|_| {
            eprintln!("❌ Error: VECTORDB_API_KEY environment variable is required!");
            std::process::exit(1);
        });
    
    println!("🔧 Testing connection to: {}", server_url);
    
    // 尝试最简单的HTTP客户端配置
    let client = Client::builder()
        .timeout(Duration::from_secs(30))
        .build()?;
    
    let url = format!("{}/database/list", server_url);
    let auth_header = format!("Bearer account={}&api_key={}", username, api_key);
    
    println!("📡 Making request to: {}", url);
    println!("🔐 Auth header: {}", auth_header);
    
    match client
        .get(&url)
        .header("Authorization", &auth_header)
        .header("Content-Type", "application/json")
        .send()
        .await
    {
        Ok(response) => {
            println!("✅ Request successful!");
            println!("   Status: {}", response.status());
            println!("   Headers: {:?}", response.headers());
            
            let text = response.text().await?;
            println!("   Response body: {}", text);
        }
        Err(e) => {
            println!("❌ Request failed: {:?}", e);
            
            // 尝试更详细的错误分析
            if e.is_timeout() {
                println!("   → This is a timeout error");
            } else if e.is_connect() {
                println!("   → This is a connection error");
            } else if e.is_request() {
                println!("   → This is a request error");
            } else if e.is_decode() {
                println!("   → This is a decode error");
            }
            
            // 尝试不带认证的请求
            println!("\n🧪 Trying without authentication...");
            match client.get(&url).send().await {
                Ok(response) => {
                    println!("✅ Request without auth successful!");
                    println!("   Status: {}", response.status());
                    let text = response.text().await?;
                    println!("   Response: {}", text);
                }
                Err(e2) => {
                    println!("❌ Request without auth also failed: {:?}", e2);
                }
            }
            
            return Err(e.into());
        }
    }
    
    Ok(())
}