By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 1,837 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 = " http://10.60.93.51/TempFile ";
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,
Angel

Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemNetWebRequestClassProxyTopic.asp

For how to use current logged user credentail, please refer to:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnetcredentialcacheclassdefaultcredentia lstopic.asp

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

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.

Browse more C# / C Sharp Questions on Bytes