rest - 在PowerShell中检查Rest Call是否成功

标签 rest powershell error-handling

我当前正在编写一个PowerShell脚本,该脚本将通过Rest API从工具中删除所有用户。当前脚本按预期工作,但缺少错误处理。我要检查的唯一一件事是是否成功完成了剩余 call 。谷歌搜索之后,我找不到很多东西,或者我搜索的是错误的术语。任何想法或方向将不胜感激!

最佳答案

这是我已成功使用的代码示例(假设您已定义Uri,Header和Body(如果需要的话,还请注意,此处的Method设置为Post)):

    try
    {
        Write-Verbose "Calling $Uri"
        Invoke-RestMethod -Uri $Uri -Method Post -Headers $Headers -Body $Json -ContentType 'application/json' -ErrorAction Stop
    }
    catch
    {
        throw $_
    }

关于rest - 在PowerShell中检查Rest Call是否成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44705690/

相关文章:

powershell - 如何使用 powershell 选择 HTML 属性值

error-handling - 如何处理这个错误?

ruby-on-rails - 标题中的 Rails RestClient 传递 token 失败

spring - 为什么 Spring JPA 将有效日期转换为无法识别的格式化字符串?

json - 如何优化此Powershell脚本,将JSON转换为CSV?

python - 如何从@commands.has_role()获取 "error"消息

validation - 使用解析器时如何在graphql-spring-boot中引发多个验证错误?

javascript - 获取在 Node/Express 中传递不同数据的相同 URL 的方法

Java仅返回父类(super class)的属性

powershell - 如何修复@{DisplayName=Firstname Lastname}