0
votes

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). 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. 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?

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

NOTE:- This Splunk endpoint starts streaming results after completing the search only.

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.

2

2 Answers

1
votes

No, but you can directly use the HttpWebRequest object you referenced instead.

I would recommend writing your own function Invoke-MyRestMethod that uses that class with parameters for R/W timeout and anything else you need.

0
votes

The MSDN page on Invoke-WebRequest indicates that there's a -TimeoutSec parameter that takes an int32. It appears that Invoke-RestMethod supports the same parameter.