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

Reading the contents of a page through its URL

P: n/a
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


Oct 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
Ignacio Machin
machin AT laceupsolutions.com
"Kuldeep" <ku****************@hotmail.comwrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
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


Oct 19 '06 #2

P: n/a
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
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:en**************@TK2MSFTNGP05.phx.gbl...
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.
--
Ignacio Machin
machin AT laceupsolutions.com
"Kuldeep" <ku****************@hotmail.comwrote in message
news:u4**************@TK2MSFTNGP02.phx.gbl...
>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



Oct 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.