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);
                }
            }
        };
    }
  • 相关阅读:
    Netty源码分析之ByteBuf引用计数
    GitHub git push大文件失败(write error: Broken pipe)完美解决
    Windows10 Docker安装详细教程
    全面的Docker快速入门教程
    十本你不容错过的Docker入门到精通书籍推荐
    CentOS 8.4安装Docker
    postgres之一条sql查询总数及部分数据
    neo4j相关操作
    git上传大文件
    分布式文件系统fastdfs安装以及python调用
  • 原文地址:https://www.cnblogs.com/flaaash/p/988744.html
Copyright © 2011-2022 走看看