http下载文件——WebClient

作者:追风剑情 发布于:2015-10-28 16:30 分类:C#

using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.Text;

namespace WebRequestTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                WebClient wc = new WebClient();
                Uri u = new Uri("http://192.168.1.211/android_res/version.txt");
                wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnDownloadStringComplete);
                wc.DownloadStringAsync(u);

                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

        private static void OnDownloadStringComplete(object sender, DownloadStringCompletedEventArgs e)
        {
            string result = e.Result;
            Console.WriteLine("下载完成:");
            Console.WriteLine(result);
        }
    }
}

运行效果:

hhhhh.png

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号