日期:2014-05-17  浏览次数:21309 次

下载文件时,出现服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF
            string fileName = "C:\\英国海外旅游(月).xls";
            string grabUrl = "http://www.ons.gov.uk/ons/rel/ott/overseas-travel-and-tourism---monthly-release/august-2012/rft--august-2012.xls";
            WebClient myWebClient = new WebClient();
            //"http://www.ons.gov.uk/ons/rel/ott/overseas-travel-and-tourism---  monthly-release/index.html";
            myWebClient.DownloadFile(grabUrl, fileName);


///另一种是

            string Url = "http://www.ons.gov.uk/ons/rel/ott/overseas-travel-and-tourism---monthly-release/august-2012/rft--august-2012.xls";
            string FileName = "C:\\英国海外旅游(月).xls";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.UserAgent = "User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
            request.Accept = "text/html, application/xhtml+xml, */*";
            request.Host = "www.ons.gov.uk";
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            if (!response.ContentType.ToLower().StartsWith("text/"))
            {
                //Value = SaveBinaryFile(response, FileName); 
                byte[] buffer = new byte[1024];
                Stream outStream = System.IO.File.Create(FileName);
                Stream inStream = response.GetResponseStream();
                int l;
                do
                {
                    l = inStream.Read(buffer, 0, buffer.Length);
                    if (l > 0)
                        outStream.Write(buffer, 0, l);
          &nb