我有一个长期运行的网页,我需要Powershell来打电话.我从任务管理器每晚运行它,具体如下:
powershell -Command "Invoke-WebRequest https://www.example.com/longrunningtask" 
但PowerShell超时发生在网站响应之前.有没有办法将超时设置为Invoke-WebRequest超过标准的60秒?
Jef*_* E. 19
-TimeoutSec调用Invoke-WebRequestcmdlet 时,应该有一个参数可以提供整数值.
Invoke-WebRequest https://www.example.com/longrunningtask -TimeoutSec 60
您也许可以通过设置静态ServicePointManager.MaxServicePointIdleTime属性来解决超时问题。默认值为 100000ms(100 秒):
# Bump it up to 180 seconds (3 minutes)
[System.Net.ServicePointManager]::MaxServicePointIdleTime = 180000
# Now run your Invoke-WebRequest after making the change
更改ServicePointManager仅适用于当前应用程序域,并且不会在会话之外持续存在(即,您需要在每次运行脚本时执行此操作)
Invoke-WebRequest -Uri "https://google.com:9811" -ConnectionTimeoutSeconds 2
Measure-Command { Invoke-WebRequest -Uri "https://google.com:99" }
Measure-Command { Invoke-WebRequest -Uri "https://google.com:99" -ConnectionTimeoutSeconds 2 }
##timeout in PS 7.4
-ConnectionTimeoutSeconds
-OperationTimeoutSeconds
| 归档时间: | 
 | 
| 查看次数: | 16587 次 | 
| 最近记录: |