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


C# NetworkCredential.IsNull方法代码示例

本文整理汇总了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;
                }
            }
        }
开发者ID:Schumix,项目名称:Schumix2,代码行数:75,代码来源:Utilities.cs


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