本文整理汇总了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;
}
示例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;
}
示例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);
}
示例4: getCountry
private string getCountry(string ip)
{
string response = new WebClient().DownloadString(API + ip);
return response.StartsWith("fail,") ? "N/A" : response.Split(',')[1].Replace("\"","");
}