【问题标题】:Why am I receiving the "Invoke-RestMethod : Not Found" error?为什么我会收到“Invoke-RestMethod:未找到”错误?
【发布时间】:2019-12-03 22:25:20
【问题描述】:

我正在尝试调用使用 Invoke_RestMethod 调用的 powershell 脚本。 powershell 脚本在同事的计算机上按原样工作,但在我的计算机上却没有,这完全一样。我收到以下错误

15:47:48.270 Invoke-RestMethod : Not Found
15:47:48.271 At C:\Program Files (x86)\TRICENTIS\Tosca Testsuite\ToscaCI\Client\deliver.ps1:15 char:1
15:47:48.272 + Invoke-RestMethod -Body $body -Method 'Post' -Uri $url

这是我调用的名为 delver.ps1 的 powershell 脚本

$url = 'https://pulse-us-east-1.qtestnet.com/webhook/b9303bb6-d0e1-43ce-bf96be4a3b330c8f'

Set-Location -Path "C:\Tosca_Projects\Tosca_Workspaces\First Steps\Test Results"

$payload = (Get-Content "result.xml" -Raw)

$body = @{
'projectId' = '95814'
'test-cycle' = '3539385'
'requiresDecode' = 'true'
'result' = $payload
}

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod -Body $body -Method 'Post' -Uri $url

我运行的是 Windows 10 Powershell 版本 5.1.17763.503,我什至升级到了 powershell 6.2.3,我得到了同样的错误

【问题讨论】:

  • 您是否尝试过使用https://postman-echo.com/post 来验证它是否适用于返回响应的 URL?我怀疑“未找到”是返回 404 响应的消息。
  • 格伦,这很有效,非常有趣......

标签: powershell powershell-core


【解决方案1】:

我最近几天多次偶然发现这个错误,甚至很难在某种意义上说是神秘的,你可能认为这是因为 cmdlet 不好玩,实际上是因为找不到 URL,基本上是 404 错误内部代码。

尝试逐步测试 de URL,并非常小心引号(它们所在的位置和结束位置)+ 可能需要转义的字符。 https://pulse-us-east-1.qtestnet.com/

祝你好运,只是要多加注意

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多