Gary Davis
asked on
Getting "underlying connection was closed..." error on HttpWebRequest()
We have a console application using HttpWebRequest on Win Server with .net 3.5. Intermittently, we get errors :
The underlying connection was closed: An unexpected error occurred on a send.
How can we correct this ?
Any advantage in adding ServicePointManager.MaxSer vicePoints and ServicePointManager.MaxSer vicePointI dleTime ?
Where would these be set ?
Thank you,
Gary Davis
The underlying connection was closed: An unexpected error occurred on a send.
How can we correct this ?
Any advantage in adding ServicePointManager.MaxSer
Where would these be set ?
Thank you,
Gary Davis
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(&.);
webReq.Method = "POST";
webReq.ContentType = "text/xml";
webReq.Headers.Add("Authorization", "Basic " + strAccount);
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = false;
HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();
Stream stream = webResp.GetResponseStream() as Stream;
byte[] buffer = new byte[32 * 1024];
int nRead = 0;
MemoryStream ms = new MemoryStream();
do
{
nRead = stream.Read(buffer, 0, buffer.Length);
ms.Write(buffer, 0, nRead);
} while (nRead > 0);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks