error receiving information from fixed IP address "The underlying connection was closed: An unexpect

A

Angel

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
 
J

Jeffrey Tan[MSFT]

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/default.asp?url=/library/en-us/cpref/html/
frlrfSystemNetWebRequestClassProxyTopic.asp

For how to use current logged user credentail, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemnetcredentialcacheclassdefaultcredentialstopic.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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top