The following function is for retrieving a web page from given URL.
bool RetrieveWebPage(String strUrl, ref String strReturn)
{
bool results = true;
try
{
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(strUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
StringBuilder strbuilder = new StringBuilder();
while (readStream.EndOfStream == false)
{
strbuilder.Append(readStream.ReadLine());
}
response.Close();
readStream.Close();
strReturn = strbuilder.ToString();
}
catch (Exception e)
{
strReturn = "";
results = false;
}
return results;
}
No comments:
Post a Comment