将令牌变量传递给PowerShell中的标头的问题

nx7onnlm  于 2022-11-10  发布在  Shell
关注(0)|答案(1)|浏览(147)

$TOKEN变量值在传递到标头后会发生变化。如何才能使$TOKEN值在传递到标头后保持不变?谢谢。

$body = @{
    username = "API"
    password = Read-Host "enter password" -MaskInput
    grant_type = "password"
};

$response = Invoke-RestMethod "https://....../oauth2/token" -Method Post -Body $body
$token = $response.access_token;
return $token

$headers = @{
    Authorization = "Bearer $token"
}

$response = Invoke-RestMethod "https://....../search-total" -Headers $headers
return $response;
tmb3ates

tmb3ates1#

已通过移动返回语句解决此问题。

相关问题