如何在ASP.NET 2.0中读取HttpResponse?
时间:2020-03-06 14:36:56 来源:igfitidea点击:
例如,我有一个由另一个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 client = new WebClient(); string response = client.DownloadString(url);
我们将需要使用HttpWebRequest和HttpWebResponse对象。我们也可以使用WebClient对象
Webclient.DownloadString()可能是我们想要的。
HttpResponse是响应HttpRequest发送回客户端的内容。如果要在服务器上处理某些内容,则可以使用Web服务调用或者页面方法来完成。但是,我不能完全确定我一开始就了解我们要做什么。
WebClient.DownloadString完全可以解决问题。我太迷糊了。.过去使用WebClient.DownloadFile时,我一直在查看HttpModule和HttpHandler。
非常感谢所有回复的人。