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


C# WebClient.StartsWith方法代码示例

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


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

示例1: GetStream

        public string GetStream(string address)
        {
            var serveralias = address.Split('/')[0];
            var filename = address.Substring(Math.Min(serveralias.Length + 1, address.Length));
            var server = "";
            var nameServers = new CSVDocument(File.ReadAllText("nameserver.csv"));
            foreach (var nameServer in nameServers)
            {
                server = new WebClient().DownloadString(string.Format(nameServer["Pattern"], serveralias)).Trim(' ', '\n', '\r');
                if (server != "") { break; }
            }

            if (!server.StartsWith("http://")) { server = "http://" + server; }
            var resolvedAddress = Path.Combine(server, filename).Replace('\\', '/');

            var siteContent = "";
            foreach (var appendage in new[] { "", ".tk", "/index.tk" })
            {
                try
                {
                    var siteRequest = ((HttpWebResponse)WebRequest.Create((resolvedAddress + appendage).Replace('\\', '/')).GetResponse());
                    siteContent = new StreamReader(siteRequest.GetResponseStream()).ReadToEnd();
                    if (!Regex.IsMatch(siteContent, "Apache.*at.*Port", RegexOptions.Singleline))
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

            return siteContent;
        }
开发者ID:Moonspawner,项目名称:HNOOO,代码行数:35,代码来源:Data.cs

示例2: Server

        private static string Server(string serveralias)
        {
            var server = "";
            var nameServers = new CSVDocument(File.ReadAllText("nameserver.csv"));
            foreach(var nameServer in nameServers) {
                try {
                    server = new WebClient().DownloadString(string.Format(nameServer["Pattern"], serveralias)).Trim(' ', '\n', '\r');
                    if(server != "") { break; }
                } catch(Exception e) { /* ignored for now */ }
            }

            if(!server.StartsWith("http://")) { server = "http://" + server; }
            return server;
        }
开发者ID:dr4yyee,项目名称:HNOOO,代码行数:14,代码来源:Data.cs

示例3: FindName

        public string FindName()
        {
            var response = new WebClient().DownloadString("http://example.com/");
            var prefix = "Hello, ";
            var suffix = "!";

            if (!response.StartsWith(prefix))
            {
                throw new NotImplementedException("The beginning of the response is invalid.");
            }

            if (!response.EndsWith(suffix))
            {
                throw new NotImplementedException("The ending of the response is invalid.");
            }

            return response.Substring(prefix.Length, response.Length - prefix.Length - suffix.Length);
        }
开发者ID:MainMa,项目名称:mockeverything,代码行数:18,代码来源:Demo.cs

示例4: getCountry

 private string getCountry(string ip)
 {
     string response = new WebClient().DownloadString(API + ip);
     return response.StartsWith("fail,") ? "N/A" : response.Split(',')[1].Replace("\"","");
 }
开发者ID:NightDevel,项目名称:IP2Country,代码行数:5,代码来源:Form1.cs


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