我有一个长期运行的网页,我需要Powershell来调用它。我每晚从任务管理器中运行它,如下所示:
powershell -Command "Invoke-WebRequest https://www.example.com/longrunningtask" 但是powershell超时发生在网站响应之前。有没有办法将Invoke-WebRequest上的超时设置为比标准的60秒更长?
发布于 2015-12-07 22:54:01
在调用Invoke-WebRequest cmdlet时,应该有一个可以向其提供整数值的-TimeoutSec参数。
Invoke-WebRequest https://www.example.com/longrunningtask -TimeoutSec 60发布于 2015-12-08 01:25:17
您可以通过设置静态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的更改仅适用于当前的应用程序域,并且不会持续到会话之后(即,您需要在每次运行脚本时执行此操作)
发布于 2020-03-12 16:27:30
下面是我已经成功尝试过的命令,让powershell发出一个包含“与”符号的web请求:
""http://localhost/index.php?option=val1""&""view=val2""&""key=val3""&""profile=2""“-Command "Invoke-WebRequest powershell -TimeoutSec 600
请注意添加的双引号,希望它对需要从命令行执行web请求的人有所帮助:)
https://stackoverflow.com/questions/34136088
复制相似问题