Esempio n. 1
0
 /// <summary>
 /// 文件下载[如果连接不是绝对路径存在跳转默认会自动跳转]
 /// 会自动分析协议头中的filename
 /// 如果分析失败则直接存储为默认名[默认为:.zip格式].
 /// 成功返回true;
 /// </summary>
 /// <param name="url">下载地址</param>
 /// <param name="paths">保存绝对路径 如:c://download//</param>
 /// <param name="cc">Cookie</param>
 /// <param name="defaultName">默认后缀</param>
 /// <returns></returns>
 public bool DonwnLoad(string url, string paths, CookieContainer cc, string defaultName = ".zip")
 {
     try
     {
         item.Url = url;
         item.Allowautoredirect = true;
         item.ResultType        = ResultType.Byte;
         item.Container         = cc;
         //item.Container = wnet.StringToCookie(url, wnet.GetCookies(url));
         hr = http.GetHtml(item);
         string strname = hr.Header["Content-Disposition"].Split(new string[] { "filename=" }, StringSplitOptions.RemoveEmptyEntries)[1];
         byte[] buffer  = hr.ResultByte;
         try
         {
             File.WriteAllBytes(paths + strname, buffer);
         }
         catch
         {
             File.WriteAllBytes(paths + defaultName, buffer);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 采用httpwebrequest方式访问网络,根据传入的URl地址,得到响应的数据字符串。
        /// </summary>
        /// <param name="objHttpItems">参数列表</param>
        /// <param name="cookie">自动维护的字符串cookie</param>
        /// <returns>HttpResults 为返回结果</returns>
        public HttpResults GetHtml(HttpItems objHttpItems, ref string cookie)
        {
            //调用专门读取数据的类
            HttpResults res = GetHttpRequestData(objHttpItems);

            cookie     = new XJHTTP().UpdateCookie(cookie, res.Cookie);
            res.Cookie = cookie;
            return(res);
        }
Esempio n. 3
0
 /// <summary>
 /// 获取服务器返回的时间,如果Header中没有Date则返回当前时间
 /// </summary>
 /// <param name="hrs">请求结果对象</param>
 /// <returns>返回本地时区Datatime数据</returns>
 public DateTime GetServerTime(HttpResults hrs)
 {
     try
     {
         return(GetTime4Gmt(hrs.Header["Date"].ToString()));
     }
     catch
     {
         return(DateTime.Now);
     }
 }