我有一个脚本可以删除资源并创建新的资源。时时刻刻,我都搞不懂为什么。当我多次运行这个脚本时,似乎就会发生这种情况,但我无法得到一个明确的模式。我发现我的服务器还没有接收到消息,因为请求还没有日志记录。
$old_values = Invoke-RestMethod -Uri $uri -Method Get
foreach($old_value in $old_values.result) {
Invoke-RestMethod -Uri "$uri&key=$old_value.id" -Method Delete
}
$new_value = Invoke-RestMethod -Uri "$uri" -Body "{}" -ContentType application/json -Method Post有趣的是,当我直接从powershell运行调用-RestMethod调用时,我会得到偶尔的超时。我也和Fiddler一起运行过,从来没有暂停过。
编辑我一直在检查与netstat的连接。当命令挂起时,它们被列为已建立的命令。但是我经常看到TIME_WAIT连接列在我的服务器上。我的关系有可能不会被关闭吗?
发布于 2014-11-05 22:07:40
上面发布的链接David包含了解决问题的解决办法:
$r = (Invoke-WebRequest -Uri $uri `
-Method 'POST' `
-ContentType 'application/json' `
-Body '{}' `
).Content | ConvertFrom-Json发布于 2017-02-14 19:55:49
我发现Allanrbo在3到4分之后仍然超时的答案。
我做了以下几点:
powershell "(Invoke-RestMethod -Method 'Delete' -Uri '$uri').Content"发布于 2018-06-01 09:40:24
很抱歉提了个老话题。我们现在使用的是Win 7和PowerShell版本3.0,我们在POST方法中遇到了同样的问题。当我们第三次发布相同的JSON时,powershell窗口将挂起。关闭并重新打开之后,它就能工作了。
为了绕开它,简单地在POST末尾添加2行:
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint('<URL>')
$ServicePoint.CloseConnectionGroup("")https://stackoverflow.com/questions/23353963
复制相似问题