本文整理汇总了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;
}
示例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;
}
示例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;
}