Solved

Getting "underlying connection was closed..." error on HttpWebRequest()

Posted on 2009-05-08
2
742 Views
Last Modified: 2013-12-17
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.MaxServicePoints and ServicePointManager.MaxServicePointIdleTime ?

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);

Open in new window

0
Comment
Question by:Gary Davis
2 Comments
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 500 total points
ID: 24348255
The problem you are facing has been officially documented by Microsoft here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599

For additional support, you may see this link too: http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx
0
 
LVL 18

Author Comment

by:Gary Davis
ID: 24400216
I have reviewed the sources and I am still seeing occasional issues so will try some different possibilities. I am closing this in any case.
Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now