question

Swabha avatar image
0 Votes"
Swabha asked MotoX80 commented

Exception calling "ReadToEnd" with "0" argument(s): "The operation has timed out."

Please find the code snippet here below as the below error is displaying while executing the script. Exception calling "ReadToEnd" with "0" argument(s): "The operation has timed out."

code snippet :

 $request = [System.Net.HttpWebRequest]::Create($Uri)
 $request.Headers["X-MC-MAC"] = $MAC
 $request.Headers["X-MC-Nonce"] = $Nonce
 $request.Timeout = 10800000
 $request.KeepAlive = $false
 $request.ProtocolVersion = [System.Net.HttpVersion]::Version10
 $request.ServicePoint.ConnectionLimit = 1;
 $response = $request.GetResponse()
windows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I don't see ReadToEnd anywhere in the code that you posted. How are trying to call it?

Is there a reason that you don't just use Invoke-WebRequest?

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-5.1

0 Votes 0 ·

1 Answer

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hi Swabha,

This occurs due to not having Exception Handling implemented there are possibly two exception can occur by which the operation has timed out i.e,

OutOfMemoryException
There is insufficient memory to allocate a buffer for the returned string.

IOException
An I/O error occurs.

I would recommend to go with following documentation and modify your script accordingly and implement Exception Handling:- https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader.readtoend?view=net-6.0

I hope this help to resolve your issue, Accept Answer if found helpful.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.