zoukankan      html  css  js  c++  java
  • TCP编程(2):WebClient,html传输及文件下载

    /*--===------------------------------------------===---
    WebClient测试

                许明会    2007年12月9日 20:17:39
    --===------------------------------------------===---
    */
    using System;
    using System.Net;

    namespace xumh
    {
        
    public class runMyApp
        {
            
    static void Main()
            {
                
    string strBaiduUri = @"http://www.baidu.com";
                
    string strDownloadUri = @"http://microphoenix.spaces.live.com/feed.rss";
                
    string strText=null;
                WebClient wc 
    = new WebClient();
                
    try
                {
                    System.IO.Stream response 
    = wc.OpenRead(strBaiduUri);
                    
    int byteRead;
                    
    do
                    {
                        byteRead 
    = response.ReadByte();
                        
    if(byteRead > 0)
                            strText 
    += Convert.ToChar(byteRead);
                    }
                    
    while (byteRead > 0);
                    Console.WriteLine(strText);
                    
    //
                    wc.DownloadFile(strDownloadUri,@"C:\feed.rss");
                    Console.WriteLine(
    "文件下载完成。");
                }
                
    catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        };
    }
  • 相关阅读:
    ZOJ 3949 Edge to the Root( 树形dp)
    CCF201812-3 CIDR合并
    CF700E E. Cool Slogans
    BZOJ4552: [Tjoi2016&Heoi2016]排序
    BZOJ3238: [Ahoi2013]差异
    BZOJ4566: [Haoi2016]找相同字符
    Codeforces Global Round 1 A~F
    (HDU)1555-- How many days? (多少天)
    (HDU)1491-- Octorber 21st (校庆)
    (HDU)1465-- 不容易系列之一
  • 原文地址:https://www.cnblogs.com/flaaash/p/988744.html
Copyright © 2011-2022 走看看