首页 > 解决方案 > 带有错误处理的 API powershell 请求

问题描述

代码目的:通过 API 向服务器发出 post 请求

我在这里的原因:当我发出帖子请求时,它会返回

Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At line:1 char:1
+ Invoke-RestMethod @restpostParams
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

我对社区
的问题:404 错误实际上是错误的,因为 POST 请求有效并发送了我需要它发送的数据。我想要一种方法来捕捉这个错误并让脚本继续运行。我一直在研究用 PS 尝试和捕捉块,但我只是不确定如何开始使用它们。有人可以指出我正确的方向吗?

标签: powershellerror-handling

解决方案


推荐阅读