例如,我有一个由另一个aspx调用的ASP.NET表单:

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

我想做这样的事情:

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

我需要得到任何Response.Write得到的结果或者去url,操纵那个响应,并发回其他东西。

非常感谢任何帮助或正确方向的观点。

有帮助吗?

解决方案

Webclient.DownloadString()可能是你想要的。

其他提示

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

您需要使用HttpWebRequest和HttpWebResponse对象。您还可以使用WebClient对象

HttpResponse是响应HttpRequest发送回客户端的东西。如果您想在服务器上处理某些内容,那么您可以使用Web服务调用或页面方法来执行此操作。但是,我并不完全确定我一开始就明白你要做什么。

WebClient.DownloadString完全成功了。我把自己弄得太干净了......当我过去使用过WebClient.DownloadFile时,我正在看HttpModule和HttpHandler。

非常感谢所有回复的人。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top