Reading the contents of a page through its URL

K

Kuldeep

Hi All,

I am trying to read the contents of a page through its URL.

My code snippet is as follows:
public void mtdGetPageDataHWR()
{
HttpWebRequest objRequ =
(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
HttpWebResponse objResp = (HttpWebResponse)objRequ.GetResponse();
string strVersion = objResp.ProtocolVersion.ToString();
StreamReader objRd = new StreamReader(objResp.GetResponseStream());
string strRd = objRd.ReadLine();
while(strRd!=null)
{
Response.Write(strRd);
strRd = objRd.ReadLine();
}
}

Is there any other way to achieve this which could be more efficient or
faster than this.

Any help on this would be very handy

Thanks,

Kuldeep
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

What is wrong with that code?

you could use a memorystream to store all the page in memory and then later
send it back in the response.
 
K

Kuldeep

Hi Machin,

Nothing is wrong with the piece of code that I showed.
All I am looking forward for is an alternative method to achieve the same.
Something which could be as dynamic as a "Ctrl + F" search on a HTML page.
With which I can avoid the overkill of reading the entire data through a
Stream Reader.

Any leads on this would be very helpful

Thanks,
Kuldeep
 

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