Friday, April 24, 2015

The underlying connection was closed: An unexpected error occurred on a receive.System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

I get following error while working with REST API and i do following code change to resolve this issue.

Error:
The underlying connection was closed: An unexpected error occurred on a receive.System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

To resolve above error add following properties to webrequest object
HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
            webRequest.KeepAlive = false;            webRequest.ProtocolVersion=HttpVersion.Version10;

Happy Coding !!  

No comments:

Post a Comment