Powershell curl 调用在第二个请求时失败

问题描述

我正在创建一个脚本来调用我的服务中的几个端点。 调用如下所示:

$scheduleResponse=(curl -Method 'POST' -Uri $baseUrl'/scheduletests' `
            -Headers @{"Accept"="application/json";"Content-Type"="application/json"} `
            -Body $body)
$scheduleContent=ConvertFrom-Json([String]::new($scheduleResponse.Content))
#Error checks here
$testId = [String]::new($scheduleContent.ScheduleTests.TestID)
$getTestResultsBody = '{"TestID":"' + $testId + '"}' #Hard-coding this value works.
$getResponse=(curl -Method 'POST' -Uri $baseUrl'/gettestresults' -Headers @{"Accept"="application/json";"Content-Type"="application/json"} -Body $getTestResultsBody)

我的 getResponse 失败并显示以下错误消息:

curl : 无法从传输连接读取数据: 连接已关闭。在 C:\Development\Services\TESTService\Test Clients\Caller.ps1:43 char:27 ... etResponse=(curl -Method 'POST' -Uri $baseUrl'/gettestresults' -Heade ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ CategoryInfo : NotSpecified: (:) [Invoke-WebRequest],IOException FullQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

我调试了我的服务,它正在接收正确的请求并发送正确的响应。 如果我在 getRequest 中对 testId 进行硬编码,则整个脚本都可以工作。所以我的猜测是它与从第一次调用中读取测试 ID 有关。 任何关于可能出错的提示

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...