Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· openaiHugging Face Suzhen/CodeChat

viết bacth trong poweshell để tự động lấy dữ liệu theo thông tin…

  1. User

    viết bacth trong poweshell để tự động lấy dữ liệu theo thông tin fetch(“https://iboard-query.ssi.com.vn/v2/stock/exchange/hose”, { “headers”: { “accept”: “application/json, text/plain, /”, “accept-language”: “vi”, }, “referrer”: “https://iboard.ssi.com.vn/”, “referrerPolicy”: “strict-origin-when-cross-origin”, “body”: null, “method”: “GET”, “mode”: “cors”, “credentials”: “omit” });

  2. Assistant

    Trong PowerShell, bạn có thể sử dụng Invoke-RestMethod để thực hiện các yêu cầu HTTP GET mà không cần một file batch theo nghĩa truyền thống. Dưới đây là một đoạn script PowerShell mà bạn có thể sử dụng để tự động hóa việc fetch dữ liệu từ URL cung cấp:

    # Đặt URL mà bạn muốn fetch dữ liệu từ đó
    $url = "https://iboard-query.ssi.com.vn/v2/stock/exchange/hose"
    
    # Thiết lập các headers
    $headers = @{
        "accept" = "application/json, text/plain, */*"
        "accept-language" = "vi"
    }
    
    # Thiết lập các tham số khác
    $referrer = "https://iboard.ssi.com.vn/"
    $referrerPolicy = "strict-origin-when-cross-origin"
    $body = $null
    $method = "GET"
    $mode = "cors"
    $credentials = "omit"
    
    # Thực hiện yêu cầu GET
    $response = Invoke-RestMethod -Uri $url -Method $method -Headers $headers
    
    # In ra kết quả
    $response | ConvertTo-Json -Depth 10
    

    Đoạn mã này sẽ gửi một yêu cầu GET đến URL được chỉ định với các headers cần thiết và sau đó in ra kết quả dưới dạng JSON. Bạn có thể lưu đoạn script này vào một file với đuôi .ps1 và chạy từ PowerShell.

    Nếu bạn muốn lưu kết quả vào một file, bạn có thể đổi dòng cuối cùng thành:

    # Lưu kết quả vào một file txt hoặc json
    $response | ConvertTo-Json -Depth 10 | Out-File -FilePath "path_to_your_output_file.json"
    

    Thay thế path_to_your_output_file.json với đường dẫn và tên file mà bạn muốn lưu.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.