我想从其他网站加载一些固定的部分到我的网络应用程序。 怎么做到这一点? 感谢。
答案 0 :(得分:6)
你可以通过以下几种方式实现:
<iframe>
ajax
加载内容并将其写入页面。WebClient
DownloadString
加载页面并将其写入您的页面。<强>更新强>
获得字符串后,您可以使用Html Agility Pack解析它并获取所需内容。 (也可在Nuget上找到)
答案 1 :(得分:5)
您可以使用WebRequest
执行此任务:
string url = "http://somesite.com/somepage.php";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string contents = reader.ReadToEnd();
//parse contents as you wish.......
reader.Close();
}
response.Close();