ytshare 2015-10-19 01:42 采纳率: 50%
浏览 4601
已结题

【求助】webclient下载文件时 报System.Net.WebException: 操作超时”

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace SH600004Quickly
{
    class Program
    {
        static void Main(string[] args)
        {
            WebClient webClient = new WebClient();
            ServicePointManager.DefaultConnectionLimit = 100; 
            string Start = "2010年04月13日";
            string End = "2013年12月31日";
            DateTime dtStart = DateTime.Parse(Start);
            DateTime dtEnd = DateTime.Parse(End);
            int Days = (dtEnd - dtStart).Days + 1;//相隔天数
            string strPath = "F:\\gupiao111111\\";



            string Stockid = "600000";

            //string aFirstName = args[0].Substring(args[0].LastIndexOf("\\") + 1, (args[0].LastIndexOf(".") - args[0].LastIndexOf("\\") - 1));
            for (int i = 0; i < Days; i++)
            {

                string url = null;
                string sDay = dtStart.AddDays(i).ToString("yyyy-MM-dd"); //每一天

                url = "http://market.finance.sina.com.cn/downxls.php?date=" + sDay + "&symbol=sh" + Stockid;

                Console.WriteLine(url);

                DirectoryInfo stockDir = Directory.CreateDirectory(strPath + sDay);
                string dataDir = stockDir.FullName + "\\data.txt";
                webClient.DownloadFile(url, dataDir);

                //webClient.Dispose();

                //WriteStr2FileEnd("C:\\Users\\T.Yang\\Desktop\\errorLog.txt", sDay + " " + aFirstName);
                //strPath = "F:\\gupiao111111\\";

            }

            //将每个文件夹里的文件用bat处理
        }

        public static void WriteStr2FileEnd(String filename, String content)//自动换行写入
        {
            FileStream fsLineNo = new FileStream(@filename, System.IO.FileMode.OpenOrCreate, FileAccess.Write);
            fsLineNo.Seek(fsLineNo.Length, SeekOrigin.Begin);
            StreamWriter swLineNo = new StreamWriter(fsLineNo);
            swLineNo.WriteLine(content);
            swLineNo.Close();
            fsLineNo.Close();
        }

    }
}

每次下载几个文件后,就卡在那不动了,怎么办?

  • 写回答

2条回答 默认 最新

  • 这个还能被注册? 2015-10-19 09:22
    关注

    WebClient webClient = new WebClient(); 把这个放FOR循环里面试试?

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作