asp.net 获取別的网页内容

来源:互联网 发布:ov7670中文版数据手册 编辑:程序博客网 时间:2024/04/29 07:50
 

using System.Net;
using System.IO;

public partial class Modules_News_Weather : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string web = "http://tw.weather.yahoo.com/";  //http://tw.weather.yahoo.com/  //http://www.baidu.com/

        WebClient wc = new WebClient();
        wc.Credentials = CredentialCache.DefaultCredentials;
        wc.Headers.Set("User-Agent", "Microsoft Internet Explorer");
        Stream resStream = wc.OpenRead(web);
        StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
        string code = sr.ReadToEnd();

        Response.Write(code);
       //很可能獲得亂碼頁面......

        string jstext = "<script LANGUAGE=/"javascript/">window.open('http://tw.weather.yahoo.com/', 'WindowName','height=400, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no')</script>";
        //ClientScript.RegisterStartupScript(this.GetType(), "js", jstext);

        resStream.Close();
    }
}

原创粉丝点击