David
David

Reputation: 315

How do I read an HttpResponse in ASP.NET 2.0?

For example, I have an ASP.NET form that is called by another aspx:

string url = "http://somewhere.com?P1=" + Request["param"];
Response.Write(url);

I want to do something like this:

string url = "http://somewhere.com?P1=" + Request["param"];
string str = GetResponse(url);
if (str...) {}

I need to get whatever Response.Write is getting as a result or going to url, manipulate that response, and send something else back.

Any help or a point in the right direction would be greatly appreciated.

Upvotes: 3

Views: 5387

Answers (5)

David
David

Reputation: 315

WebClient.DownloadString totally did the trick. I got myself too wrapped up in this one.. I was looking at HttpModule and HttpHandler, when I had used WebClient.DownloadFile in the past.

Thank you very much to all who've replied.

Upvotes: 0

Bryant
Bryant

Reputation: 8670

An HttpResponse is something that is sent back to the client in response to an HttpRequest. If you want process something on the server, then you can probably do it with either a web service call or a page method. However, I'm not totally sure I understand what you're trying to do in the first place.

Upvotes: 0

Quintin Robinson
Quintin Robinson

Reputation: 82375

Webclient.DownloadString() is probably want you want.

Upvotes: 3

Darren Kopp
Darren Kopp

Reputation: 77657

You will need to use the HttpWebRequest and HttpWebResponse objects. You could also use the WebClient object

Upvotes: 1

John Sheehan
John Sheehan

Reputation: 78152

WebClient client = new WebClient();
string response = client.DownloadString(url);

Upvotes: 8

Related Questions