简体   繁体   English

如何更改Powershell Invoke-WebRequest或Invoke-RestMethod的ReadWriteTimeout?

[英]how to change ReadWriteTimeout for powershell Invoke-WebRequest or Invoke-RestMethod?

We are trying to download search results from Splunk using the below mentioned Rest API endpoint through PowerShell Invoke-RestMethod and Invoke-WebRequest methods(both work). 我们正在尝试通过PowerShell Invoke-RestMethod和Invoke-WebRequest方法使用下面提到的Rest API终结点从Splunk下载搜索结果(两者都可以)。 But some of our searches run for longer than 5 minutes due to which no data is returned to be written into a local file by Powershell's Invoke-RestMethod and Invoke-WebRequest methods and hence requests are timed out exactly after 5 mintues. 但是我们的某些搜索运行时间超过5分钟,因此,Powershell的Invoke-RestMethod和Invoke-WebRequest方法不会将任何数据返回写入本地文件,因此请求在5分钟后才完全超时。 We want to increase the ReadWriteTimeout mentioned on https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.readwritetimeout(v=vs.110).aspx page for Powershell's Invoke-RestMethod and Invoke-WebRequest methods, is it possible? 我们希望增加https://msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest.readwritetimeout(v=vs.110).aspx页上提到的Powershell的Invoke-RestMethod和Invoke-WebRequest的ReadWriteTimeout方法,有可能吗?

Splunk Rest API Endpoint: https://${server}:port/services/search/jobs/export Splunk Rest API端点: https:// $ {server}:port / services / search / jobs / export

NOTE:- This Splunk endpoint starts streaming results after completing the search only. 注:-此Splunk端点仅在完成搜索后才开始流式传输结果。

Many might suggest to use another CURL client for making this Rest API call, we have already tried that and it's working since other clients like curl in Cygwin don't have the default 5 minute ReadWriteTimeout. 许多人可能建议使用另一个CURL客户端来进行此Rest API调用,我们已经尝试过了,并且可以正常工作,因为Cygwin中的curl等其他客户端没有默认的5分钟ReadWriteTimeout。

No, but you can directly use the HttpWebRequest object you referenced instead. 否,但是您可以直接使用引用的HttpWebRequest对象。

I would recommend writing your own function Invoke-MyRestMethod that uses that class with parameters for R/W timeout and anything else you need. 我建议您编写自己的函数Invoke-MyRestMethod ,该函数将该类与R / W超时以及您需要的其他任何参数一起使用。

The MSDN page on Invoke-WebRequest indicates that there's a -TimeoutSec parameter that takes an int32 . Invoke-WebRequest上MSDN页面指示存在一个采用int32-TimeoutSec参数。 It appears that Invoke-RestMethod supports the same parameter. 看来Invoke-RestMethod支持相同的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM