当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.IsNotNull方法代码示例

本文整理汇总了C#中System.IO.StreamReader.IsNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.IsNotNull方法的具体用法?C# StreamReader.IsNotNull怎么用?C# StreamReader.IsNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.IsNotNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRemoteHtmlCode2

 /// <summary>
 /// 获取远程文件源代码 good HttpWebRequest
 /// </summary>
 /// <param name="url">url</param>
 /// <param name="encoding">编码</param>
 /// <param name="timeout">超时时间</param>
 /// <returns>获取远程文件源代码 线程安全</returns>
 public static string GetRemoteHtmlCode2(string url, System.Text.Encoding encoding = null, int timeout = 0) {
     url += (url.IndexOf("?") >= 0 ? "&time=" : "?time=") + Rand.RndDateStr();
     string s = ""; HttpWebResponse response = null; StreamReader stream = null;
     try {
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
         if (timeout > 1) request.Timeout = timeout;
         response = (HttpWebResponse)request.GetResponse();
         stream = new StreamReader(response.GetResponseStream(), encoding.IfNull(Encoding.UTF8));
         s = stream.ReadToEnd();
     } catch {
     } finally {
         if (stream.IsNotNull()) stream.Close();
         if (response.IsNotNull()) response.Close();
     }
     return s;
 }
开发者ID:pczy,项目名称:Pub.Class,代码行数:23,代码来源:Net2.cs

示例2: GetRemoteHtmlCode3

 /// <summary>
 /// 获取远程文件源代码 HttpWebRequest UserAgent + Referer + AllowAutoRedirect
 /// </summary>
 /// <param name="url">url</param>
 /// <param name="encoding">编码</param>
 /// <param name="timeout">超时时间</param>
 /// <returns>获取远程文件源代码</returns>
 public static string GetRemoteHtmlCode3(string url, System.Text.Encoding encoding = null, int timeout = 0) {
     url += (url.IndexOf("?") >= 0 ? "&time=" : "?time=") + Rand.RndDateStr();
     string s = ""; HttpWebResponse response = null; StreamReader stream = null;
     try {
         HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
         request.AllowAutoRedirect = true;
         if (timeout > 1) request.Timeout = timeout;
         request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
         request.Referer = url;
         response = (HttpWebResponse)request.GetResponse();
         stream = new StreamReader(response.GetResponseStream(), encoding.IfNull(Encoding.UTF8));
         s = stream.ReadToEnd();
     } catch {
     } finally {
         if (stream.IsNotNull()) stream.Close();
         if (response.IsNotNull()) response.Close();
     }
     return s;
 }
开发者ID:pczy,项目名称:Pub.Class,代码行数:26,代码来源:Net2.cs

示例3: GetRemoteHtmlCode

 private static string GetRemoteHtmlCode(string url, System.Text.Encoding encoding, int timeout = 3000)
 {
     string content = string.Empty;
     HttpWebResponse response = null; StreamReader stream = null;
     try {
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
         request.Timeout = timeout;
         response = (HttpWebResponse)request.GetResponse();
         stream = new StreamReader(response.GetResponseStream(), encoding);
         content = stream.ReadToEnd();
     } catch { } finally {
         if (stream.IsNotNull()) stream.Close();
         if (response.IsNotNull()) response.Close();
     }
     return content;
 }
开发者ID:jango2015,项目名称:SendEmail,代码行数:16,代码来源:IPHelper.cs


注:本文中的System.IO.StreamReader.IsNotNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。