asp.net page read response from another site?

S

soni2926

Hi,
I wanted to make a page where I can send a request to another page,
and read it's response back, can someone point me to an example? it's
just a basic page i need to hit, i can hit it directly with my
browser, no user/pass, but i want to read whats returned into a
webpage, it's going to come back as html, wasn't sure if there's a
control to just display whats returned, otherwise i can parse it, but
main thing was how to send a request to another page and catch the
response back.

Thanks!
 
N

Nathan Sokalski

Take a look at:

http://www.4guysfromrolla.com/webtech/070601-1.shtml

The two key classes you will be using are WebClient and UTF8Encoding. Also,
take note that even though the example on this page gets generated HTML, the
same process can be used for pretty much any type of data (for example, you
could generate another type of text file such as XML, or even non-text stuff
such as images or anything else you can make a file return, I have a few
examples of doing this if you need them). Good Luck!
 
C

Cowboy \(Gregory A. Beamer\)

Here is how I would handle this:

string url = http://www.somesite.com/somepage.html;
HttpWebRequest request = HttpWebRequest.Create(url);
HttpWebResponse response = request.GetResponse();

You can then stream it into output

StreamReader reader = new StreamReader(response.GetResponseStream);
string responseString = reader.ReadToEnd();

You can also process the stream as it comes across.
string line;
while(null != (line = reader.ReadLine())
{
//Get rid of lines you do not want, etc.
}

I like this method, as it gives you a lot of control. I would have to look,
as you might be able to do this, as well.

//Per http://www.4guysfromrolla.com/webtech/070601-1.shtml
StreamReader reader = new StreamReader(objWebClient.DownloadData(strURL));

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 

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