C#使用XMLHTTP获得网页源代码

using System;
using MSXML2;//引用COM:Microsoft XML, v3.0

namespace ConsoleApplication1
{

    class Program
    {
        static void Main(string[] args)
        {
            XMLHTTP xmlhttp = new XMLHTTP();
            string url = "http://www.526net.com/";
            xmlhttp.open("GET", url, false, null, null);
            xmlhttp.send("");
            Byte[] b = (Byte[])xmlhttp.responseBody;
            string content = System.Text.ASCIIEncoding.UTF8.GetString(b, 0, b.Length);
            //string content = System.Text.Encoding.GetEncoding("GB2312").GetString(b).Trim();
            Console.WriteLine(content);

            Console.ReadKey();
        }
    }

}

 

发表评论

您的电子邮箱地址不会被公开。