本文整理汇总了C#中System.Net.NetworkCredential.IsNull方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkCredential.IsNull方法的具体用法?C# NetworkCredential.IsNull怎么用?C# NetworkCredential.IsNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.NetworkCredential
的用法示例。
在下文中一共展示了NetworkCredential.IsNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadString
public string DownloadString(string url, int timeout, string Contains, NetworkCredential credential, int maxlength = 0)
{
lock(WriteLock)
{
try
{
var request = (HttpWebRequest)WebRequest.Create(url);
var th = new Thread(() =>
{
if(timeout > 0)
Thread.Sleep(timeout);
else
Thread.Sleep(13*1000);
if(!request.IsNull())
request.Abort();
});
if(timeout > 0)
{
request.Timeout = timeout;
request.ReadWriteTimeout = timeout;
}
else
{
request.Timeout = 10*1000;
request.ReadWriteTimeout = 10*1000;
}
request.AllowAutoRedirect = true;
request.UserAgent = Consts.SchumixUserAgent;
request.Referer = Consts.SchumixReferer;
if(!credential.IsNull())
request.Credentials = credential;
int length = 0;
byte[] buf = new byte[1024];
var sb = new StringBuilder();
using(var response = (HttpWebResponse)request.GetResponse())
{
using(var stream = response.GetResponseStream())
{
if(maxlength == 0)
maxlength = 10000;
while((length = stream.Read(buf, 0, buf.Length)) != 0)
{
if(sb.ToString().Contains(Contains) || sb.Length >= 10000)
break;
buf = Encoding.Convert(Encoding.GetEncoding(response.CharacterSet), Encoding.UTF8, buf);
sb.Append(Encoding.UTF8.GetString(buf, 0, length));
}
}
}
buf = null;
if(!th.IsNull())
{
th.Interrupt();
th = null;
}
return WebUtility.HtmlDecode(sb.ToString());
}
catch(Exception e)
{
Log.Debug("Utilities", sLConsole.GetString("Failure details: {0}"), "(DownloadString) " + e.Message);
return string.Empty;
}
}
}