本文整理汇总了C#中System.Net.Http.Headers.HttpRequestHeaders.TryGetValues方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestHeaders.TryGetValues方法的具体用法?C# HttpRequestHeaders.TryGetValues怎么用?C# HttpRequestHeaders.TryGetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.Headers.HttpRequestHeaders
的用法示例。
在下文中一共展示了HttpRequestHeaders.TryGetValues方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCookies
private static IEnumerable<CookieHeaderValue> GetCookies(HttpRequestHeaders header)
{
var result = new System.Collections.ObjectModel.Collection<CookieHeaderValue>();
IEnumerable<string> cookies;
if (header.TryGetValues("Cookie", out cookies))
{
foreach (string cookie in cookies)
{
CookieHeaderValue cookieHeaderValue;
if (CookieHeaderValue.TryParse(cookie, out cookieHeaderValue))
result.Add(cookieHeaderValue);
}
}
return result;
}
示例2: GetHeaderValue
private static string GetHeaderValue(IAbpAntiForgeryManager manager, HttpRequestHeaders headers)
{
IEnumerable<string> headerValues;
if (!headers.TryGetValues(manager.Configuration.TokenHeaderName, out headerValues))
{
return null;
}
var headersArray = headerValues.ToArray();
if (!headersArray.Any())
{
return null;
}
return headersArray.Last().Split(", ").Last();
}
示例3: IsValidHeaderPresent
public static bool IsValidHeaderPresent(HttpRequestHeaders headers, out string divisionKey)
{
IEnumerable<string> values;
if (!headers.TryGetValues("X-MAG-API-KEY", out values))
{
divisionKey = null;
return false;
}
divisionKey = values.FirstOrDefault();
if (divisionKey == null)
{
return false;
}
return divisionKey == "JPC" || divisionKey == "MSS";
}
示例4: GetReferringService
public static string GetReferringService(HttpRequestHeaders headers)
{
if (headers == null) return StatsdConstants.Undefined;
// fetch referring service from request headers
IEnumerable<string> headerValues;
if (headers.TryGetValues(StatsdConstants.OtReferringservice, out headerValues))
{
var otReferringservice = headerValues.FirstOrDefault();
if (!string.IsNullOrEmpty(otReferringservice))
{
var matchRefService = Regex.Match(
otReferringservice,
UserAgentRe,
RegexOptions.IgnoreCase);
return matchRefService.Success ?
matchRefService.Groups[1].Value.Replace('.', '_') :
otReferringservice.Replace('.', '_');
}
}
// fetch user agent from request headers
var match = Regex.Match(
headers.UserAgent.ToString(),
UserAgentRe,
RegexOptions.IgnoreCase);
var userAgent = (match.Success) ? match.Groups[1].Value.Replace('.', '_') : null;
if (!string.IsNullOrEmpty(userAgent))
userAgent = new string(userAgent.Take(MaxUserAgentLength).ToArray());
return userAgent ?? "undefined";
}
示例5: GetHeaderValues
public static List<string> GetHeaderValues(HttpRequestHeaders headers, string headerName)
{
List<string> list = new List<string>();
IEnumerable<string> values;
headers.TryGetValues(headerName, out values);
if (values != null)
{
list.Add((values.FirstOrDefault() ?? string.Empty).TrimStart(null));
}
return list;
}
示例6: ExtractTokenValue
private string ExtractTokenValue(HttpRequestHeaders headers)
{
IEnumerable<string> tokenValues;
headers.TryGetValues("authToken",out tokenValues);
return tokenValues == null ? null : tokenValues.SingleOrDefault();
}