我正在尝试使用带有websession的powershell invoke-restmethod访问基于Swagger的API(希望)捕获我需要做post方法的cookie /会话信息.我首先要求CSRF
$CSRF = Invoke-RestMethod -Uri ($Uri+'csrf-token') -Method Get -Credential $Creds -ContentType 'application/json'-SessionVariable websession
Run Code Online (Sandbox Code Playgroud)
我可以看到正确的令牌值没有任何问题.看看websession变量我确实有一些数据,但我根本没有得到任何cookie值.因此,如果我使用会话变量提交第二个请求:
Invoke-RestMethod -Method Post -Uri ($Uri+'post') -Headers $Header -Body $Body -Credential $creds -WebSession $websession
Run Code Online (Sandbox Code Playgroud)
它由于缺少cookie值而失败.如果我通过Firefox执行正常请求,我会看到带有jsessionid等的cookie,但我不知道如何在我可以使用它们的地方获取这些值(请原谅我这里的无知 - 我对invoke-rest方法相对较新在PS)