2010-04-20 54 views
2

可以通过page_load在互联网上对另一页进行请求吗?我的意思是,如果可以从其他页面获取信息并将其显示在我的aspx站点上?例如这样的事情:从aspx网站请求另一页

protected void Page_Load(object sender, EventArgs e) 
{ 
    UnknownType anotherSite = GetMarkupCode("www.fifa.com"); 
    //parse anotherSite 
      . 
      . 
      . 
    //display parsed informations 
      . 
      . 
      . 
} 

如果有可能我该怎么做?非常感谢您的回答。

回答

4

用户可以使用Web客户端类。

WebClient webClient = new WebClient(); 
Stream data = webClient.OpenRead("http://www.fifa.com"); 
StreamReader streamReader = new StreamReader(data); 
string html = streamReader.ReadToEnd(); 

编辑:感谢卢卡斯

WebClient webClient = new WebClient(); 
string html = webClient.DownloadString("http://www.fifa.com"); 
+1

在这种情况下,只使用'string html = webClient.DownloadString(“http://www.fifa.com”);',而不是打开它作为一个流。 – 2010-04-20 07:05:57

+1

谢谢!我不知道那里有!暂时不用WebClient。编辑了包含的答案。 – 2010-04-20 07:09:28

+0

这完全是我想要的:)感谢罗宾日和卢卡斯琼斯。 – sanjuro 2010-04-20 07:21:05

1

为什么不使用iframe并将iframe的来源设置为请求的页面url?

+0

我的“假设”一个简单的版本是,他要解析HTML,以便从中获取信息的某些位。不只是在iframe中显示整个页面。 – 2010-04-20 07:10:05

+0

是的,你是对的 – sanjuro 2010-04-20 07:21:48