powershell测试用utf-8
📅 2026/8/2 22:10:44
👁️ 阅读次数
📝 编程学习
# 1. 定义接口地址 $url = "http://localhost:8080/api/chat/ask" # 2. 定义一个包含多个测试用例的数组 $testCases = @( @{ question = "流量超套怎么收费?"; type = "概念类" }, @{ question = "我这个月话费为什么这么高?"; type = "事实类" }, @{ question = "宽带坏了怎么报修?"; type = "概念类" }, @{ question = "帮我查一下上个月的账单。"; type = "事实类" }, @{ question = "怎么办理拆机?"; type = "概念类" } ) Write-Host "开始批量测试沃慧答智能客服...`n" -ForegroundColor Green # 3. 循环发送每一个请求 foreach ($case in $testCases) { $jsonBody = @" { "phoneNumber": "13000000000", "question": "$($case.question)" } "@ $utf8Body = [System.Text.Encoding]::UTF8.GetBytes($jsonBody) Write-Host "[$($case.type)] 提问: $($case.question)" -ForegroundColor Cyan try { $response = Invoke-RestMethod -Uri $url -Method Post -Body $utf8Body -ContentType "application/json" Write-Host " 回答: $response`n" -ForegroundColor Yellow } catch { Write-Host " 请求失败: $($_.Exception.Message)`n" -ForegroundColor Red } } Write-Host "所有测试已完成。" -ForegroundColor Green
编程学习
技术分享
实战经验