本文整理汇总了C#中System.Net.Http.HttpClient.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.Substring方法的具体用法?C# HttpClient.Substring怎么用?C# HttpClient.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.Substring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadProblemRankings
public static ProblemRanking[] LoadProblemRankings()
{
var s = new HttpClient().GetStringAsync("https://davar.icfpcontest.org/rankings.js").Result;
JObject v = (JObject)JsonConvert.DeserializeObject(s.Substring(11));
var problems = v["data"]["settings"].ToObject<ProblemRanking[]>();
return problems;
}
示例2: GetAmazonProductPrice
// Amazon UK price history can be checked in uk.camelcamelcamel.com, for example: http://uk.camelcamelcamel.com/Sennheiser-Professional-blocking-gaming-headset-Black/product/B00JQDOANK
private static double? GetAmazonProductPrice(string p_amazonProductUrl)
{
string errorMessage = String.Empty;
double price = 0.0;
var webpage = new HttpClient().GetStringAsync(p_amazonProductUrl).Result;
Utils.Logger.Info("HttpClient().GetStringAsync returned: " + ((webpage.Length > 100) ? webpage.Substring(0, 100) : webpage));
// <span id="priceblock_ourprice" class="a-size-medium a-color-price">£199.95</span>
string searchStr = @"id=""priceblock_ourprice"" class=""a-size-medium a-color-price"">";
int startInd = webpage.IndexOf(searchStr);
if (startInd == -1)
{ // it is expected (not an exception), that sometimes Amazon changes its website, so we will fail. User will be notified.
Utils.Logger.Info($"searchString '{searchStr}' was not found.");
return null;
}
int endInd = webpage.IndexOf('<', startInd + searchStr.Length);
if (endInd == -1)
{ // it is expected (not an exception), that sometimes Amazon changes its website, so we will fail. User will be notified.
Utils.Logger.Info($"'<' after searchString '{searchStr}' was not found.");
return null;
}
string priceStr = webpage.Substring(startInd + searchStr.Length + 1, endInd - (startInd + searchStr.Length + 1));
if (!Double.TryParse(priceStr, out price))
{
Utils.Logger.Info($"{priceStr} cannot be parsed to Double.");
return null;
}
return price;
}