views:

1330

answers:

5

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.

+8  A: 
WebClient client = new WebClient();
string response = client.DownloadString(url);
John Sheehan
+1  A: 

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

Darren Kopp
+3  A: 

Webclient.DownloadString() is probably want you want.

Quintin Robinson
Answered before I saw John Sheehan had the same answer.
Quintin Robinson
A: 

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.

Bryant
A: 

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.

David