"Operation has been disabled" error when calling Invoke-WebRequest

We use Invoke-WebRequest

PowerShell in several scripts that run sequentially for about 10 minutes.

We are trying to understand why, in some rare cases, the message System.Net.WebException

is issued with the message:

Operation completed

Reading the article Understanding the MaxServicePointIdleTime and DefaultConnectionLimit indicates that the timeout is when the connection limit has been reached. Increasing the connection limit doesn't seem like a fix for the root cause of the problem.

This makes us think that our scripts do not destroy all of their resources after they have finished. What is the recommended usage Invoke-WebRequest

that allocates all resources?

We are currently doing:

$response = Invoke-WebRequest -uri $uri_1 -ContentType $mime
// do stuff with $response variable

$response = Invoke-WebRequest -uri $uri_2 -ContentType $mime    
// do stuff with $response variable

      

+3


source to share


1 answer


If you do $response | get-member

, you can see that the object HtmlWebResponseObject

has a method Dispose

, so you should be able to remove the connection by doing:

$response.Dispose() 

      



after you are done with it.

+1


source







All Articles