powershell - 带有错误处理的 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 尝试和捕捉块,但我只是不确定如何开始使用它们。有人可以指出我正确的方向吗?
解决方案
推荐阅读
- data-structures - 嵌套循环最有效的数据结构?
- java - 无法将 json 测试数据文件读入我的 stepDef
- python - 代码在字符串拆分中未按预期工作
- php - 我试图将数据添加到数据库中的用户表中
- java - 不仅为工作区创建启动配置,还为该特定语言创建启动配置
- python - 如何使用列表理解来输出列表中的昆虫数量?
- abp - ABP.IO 自定义基本主题编译错误
- php - 使用 %name% PHP + Mysql 标签在 TinyMCE 编辑器中键入文本时按名称调用用户
- python - 将 numba 用于树结构的准则是什么?
- cross-domain - 介子构建:如何使用编译库而不是将其作为子项目下载并构建