• HttpWebResponse得文件长度 可以用ContentLength, 也可以读headers


    long lFileLength = -1//文件长度
    lFileLength = webResponse.ContentLength;
    if (lFileLength == -1)
    {
         Match match = new Regex(@"(?<=(content-length:\s*))\d+", RegexOptions.IgnoreCase).Match(webResponse.Headers.ToString());
         if (match != null)
         {
          try
            {
                 lFileLength = long.Parse(match.ToString());
            }catch{}
          }
    }
    有时用fiddler, httpwatch都能看到content-length,但.net的contentlength就是读不出来,可以用正则表达式自己找出来。

    有时服务器确定没返回文件长度,只能慢慢读了。

  • 相关阅读:
    Socket listen 简要分析
    Socket connect 等简要分析
    HIVE函数大全
    元数据管理
    flume
    shell编程
    数据仓库集锦
    数据库知识
    hive sql 转化mapreduce原理
    Hadoop 学习笔记
  • 原文地址:https://www.cnblogs.com/barrysgy/p/2227670.html
Copyright © 2020-2023  润新知