srinivas

srinivas

  • NA
  • 94
  • 569

Getting Exception while running from EXE.

Jul 20 2018 8:30 AM
HI 
This is Srinivas,
 
I tried to getting web respone  of url from Windows/console, code is working fine whle its runnning from appilication but returns exception while its running from EXE, same behaviuor follow in console appilication also.
 
The Error:-  The underlying connection was closed: The connection was closed unexpectedly. 
 
Code is :-
 
public void GetResponse()
{
string spp = "http://www.somewebsite.in/";
String result = GetPageContent(spp);
label2.Text = result;
}
 
public string GetPageContent(string FullUri)
{
try
{
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(FullUri);
// Request response:
WebResponse Response = WebRequestObject.GetResponse();
// Open data stream:
Stream WebStream = Response.GetResponseStream();
// Create reader object:
StreamReader Reader = new StreamReader(WebStream);
// Read the entire stream content:
string PageContent = Reader.ReadToEnd();
// Cleanup
Reader.Close();
WebStream.Close();
Response.Close();
// return PageContent;
return "Success";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
 
Please help me. 
 

Answers (2)