木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2008-03-28 👁 6241 👍 0 💬 0 🔄 来源:本站原创
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.mzwu.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();
        }
    }

}

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 ASP获取图片的高度和宽度 下一篇 → 查找资料的常用方法