472,119 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

error receiving information from fixed IP address "The underlying connection was closed: An unexpected error occurred on a receive."

I'm trying to connect to a fixed IP address (eg. http://10.60.903.50/TempFile) in order to retrieve one accii line of text in TempFile.

I try to read the information with this code:
string fullpath = " ";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(fullpath);
//req.KeepAlive = false;
HttpWebResponse res;
StreamReader sr;
string strResult = "";

res = (HttpWebResponse) req.GetResponse(); // <--- this line brings the error
sr = new StreamReader(res.GetResponseStream(), Encoding.ASCII);
txt_compTemp.Text = sr.ToString();
In the GetRespones, I get the error: "The underlying connection was closed: An unexpected error occurred on a receive. ". I read in an article that a possible solution would be to make the KeepAlive property of HttpWebRequest to False. It kept on giving me the error (That's why it's commented).

What else should I try?

Thank you,

Nov 15 '05 #1
1 2824

Hi Angel,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, when you using HttpWebResponse.GetResponse
method to receive data, "The underlying connection was closed: An
unexpected error occurred on a receive. " error generated.

Based on my experience, the problem may due to network issue. Perhaps you
are using a proxy server? If so, you'd have to create a WebProxy object
and use the Proxy property on the HttpWebRequest to set the proxy.
Also, your proxy may need credential to access, you can specify the
credential through NetworkCredential class. Normally, if you want to use
credentials of the currently
logged in user, you can refer to CredentialCache.DefaultCredentials instead
of specifying the password and username explicitly.

There is a sample in the WebRequest.Proxy Property document below:

For how to use current logged user credentail, please refer to:
frlrfsystemnetcredentialcacheclassdefaultcredentia lstopic.asp

Please apply my suggestion above and let me know if it helps resolve your

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.