本文整理汇总了C#中System.Net.WebHeaderCollection.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# WebHeaderCollection.GetValues方法的具体用法?C# WebHeaderCollection.GetValues怎么用?C# WebHeaderCollection.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebHeaderCollection
的用法示例。
在下文中一共展示了WebHeaderCollection.GetValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TableStorageResponse
public TableStorageResponse(HttpStatusCode statusCode, string response, WebHeaderCollection headers)
{
StatusCode = statusCode;
Body = String.IsNullOrEmpty(response) ? null : new TableStorageResponseBody(response);
var values = headers.GetValues(StorageHttpConstants.HeaderNames.PrefixForTableContinuation + StorageHttpConstants.HeaderNames.NextRowKey);
NextRowKey = values != null ? values.FirstOrDefault() : null;
values = headers.GetValues(StorageHttpConstants.HeaderNames.PrefixForTableContinuation + StorageHttpConstants.HeaderNames.NextPartitionKey);
NextPartitionKey = values != null ? values.FirstOrDefault() : null;
}
开发者ID:yvesgoeleven,项目名称:NHibernate.Windows.Azure.Storage.Driver,代码行数:13,代码来源:TableStorageResponse.cs
示例2: GetRemoteNzbFilename
private string GetRemoteNzbFilename(WebHeaderCollection whc)
{
try
{
foreach (string key in whc.Keys)
{
string value = whc.GetValues(key)[0];
if (key == "X-DNZB-Name")
{
return value;
}
if (key == "Content-Disposition")
{
int start = value.IndexOf("filename=") + 9;
int end = value.IndexOf(".nzb");
int length = end - start;
return value.Substring(start, length).TrimStart('\"', ' ').TrimEnd('\"', ' ');
}
}
}
catch (Exception)
{
return "unknown";
}
return "unknown";
}
示例3: MapHeaders
public Dictionary<string, string> MapHeaders(WebHeaderCollection headerCollection)
{
var headers = new Dictionary<string, string>();
for (var i = 0; i < headerCollection.Count; i++)
{
headers.Add(headerCollection.GetKey(i), string.Join(",", headerCollection.GetValues(i)));
}
return headers;
}
示例4: AddHeaders
public void AddHeaders(WebHeaderCollection headers)
{
if (headers != null)
{
Headers = new List<Header>();
for (int i = 0; i < headers.Count; ++i)
{
string header = headers.GetKey(i);
foreach (string value in headers.GetValues(i))
{
Headers.Add(new Header(header, value));
}
}
}
}
示例5: Test_WebHeader_01
public static void Test_WebHeader_01()
{
WebHeaderCollection headers = new WebHeaderCollection();
headers.Add("xxx", "yyy");
headers.Add("xxx", "yyy222");
headers.Add("zzz", "fff");
headers.Add("xxx", "ttt");
for (int i = 0; i < headers.Count; ++i)
{
string key = headers.GetKey(i);
foreach (string value in headers.GetValues(i))
{
Trace.WriteLine("{0}: {1}", key, value);
}
}
}
示例6: AddCanonicalizedHeaders
/// <summary>
/// Add x-ms- prefixed headers in a fixed order.
/// </summary>
/// <param name="headers">The headers.</param>
/// <param name="canonicalizedString">The canonicalized string.</param>
internal static void AddCanonicalizedHeaders(WebHeaderCollection headers, CanonicalizedString canonicalizedString)
{
CultureInfo sortingCulture = new CultureInfo("en-US");
StringComparer sortingComparer = StringComparer.Create(sortingCulture, false);
// Look for header names that start with x-ms-, then sort them in case-insensitive manner.
List<string> httpStorageHeaderNameArray = new List<string>();
foreach (string key in headers.Keys)
{
if (key.StartsWith(Constants.HeaderConstants.PrefixForStorageHeader, StringComparison.OrdinalIgnoreCase))
{
httpStorageHeaderNameArray.Add(key.ToLowerInvariant());
}
}
httpStorageHeaderNameArray.Sort(sortingComparer);
// Now go through each header's values in the sorted order and append them to the canonicalized string.
foreach (string key in httpStorageHeaderNameArray)
{
StringBuilder canonicalizedElement = new StringBuilder(key);
string delimiter = ":";
// Go through values, unfold them, and then append them to the canonicalized element string.
string[] values = headers.GetValues(key);
if (values.Length == 0 || string.IsNullOrEmpty(values[0]))
{
continue;
}
foreach (string value in values)
{
// Unfolding is simply removal of CRLF.
string unfoldedValue = value.TrimStart().Replace("\r\n", string.Empty);
// Append it to the canonicalized element string.
canonicalizedElement.Append(delimiter);
canonicalizedElement.Append(unfoldedValue);
delimiter = ",";
}
// Now, add this canonicalized element to the canonicalized header string.
canonicalizedString.AppendCanonicalizedElement(canonicalizedElement.ToString());
}
}
示例7: GetRemoteNzbCategory
private string GetRemoteNzbCategory(WebHeaderCollection whc)
{
try
{
foreach (string key in whc.Keys)
{
string value = whc.GetValues(key)[0];
if (key == "X-DNZB-Category")
{
return value;
}
}
}
catch (Exception)
{
return String.Empty;
}
return String.Empty;
}
示例8: CanonicalizedUCloudHeaders
private static string CanonicalizedUCloudHeaders(WebHeaderCollection header)
{
string canoncializedUCloudHeaders = string.Empty;
SortedDictionary<string, string> headerMap = new SortedDictionary<string, string> ();
for (int i = 0; i < header.Count; ++i) {
string headerKey = header.GetKey (i);
if (headerKey.ToLower().StartsWith ("x-ucloud-")) {
foreach (string value in header.GetValues(i)) {
if (headerMap.ContainsKey (headerKey)) {
headerMap [headerKey] += value;
headerMap [headerKey] += @",";
} else {
headerMap.Add (headerKey, value);
}
}
}
}
foreach (KeyValuePair<string, string> item in headerMap) {
canoncializedUCloudHeaders += (item.Key + @":" + item.Value + @"\n");
}
return canoncializedUCloudHeaders;
}
示例9: GetConnectionResponse
private bool GetConnectionResponse(WebHeaderCollection whc)
{
try
{
foreach (string key in whc.Keys)
{
string value = whc.GetValues(key)[0];
if (key == "Connection")
{
if (value.Contains("close")) //Look if the connection was closed (NZB was not returned) - NZBMatrix returns close for Valid Requests
return false; //Will this always work??
return true; //Return true
}
}
}
catch (Exception)
{
return false;
}
return false;
}
示例10: GetCookieString
private static string GetCookieString(WebHeaderCollection webHeaderCollection)
{
try
{
string CokString = "";
for (int i = 0; i < webHeaderCollection.Count; i++)
{
String header__ = webHeaderCollection.GetKey(i);
if (header__ != "Set-Cookie")
continue;
String[] values = webHeaderCollection.GetValues(header__);
if (values.Length < 1)
continue;
foreach (string v in values)
if (v != "")
CokString += MrHTTP.StripCokNameANdVal(v)+";";
}
if (CokString.Length > 0)
return CokString.Substring(0, CokString.Length - 1);
return CokString;
}
catch { return ""; }
}
示例11: GetAllShippingMethods
//.........这里部分代码省略.........
{
Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Hight > 105: height should be in cm");
return methods;
}
var orderHeightCulture = decimal.Parse(orderHeight.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU"));
var orderLength = orderInfo.OrderLines.Sum(x => x.ProductInfo.Length);
if (orderLength < 5)
{
orderLength = 5;
}
if (orderLength > 105)
{
Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Length > 105: length should be in cm");
return methods;
}
var widthOrLength = orderWidth;
if (orderLength > orderWidth)
{
widthOrLength = orderLength;
}
var girth = 2*(Math.Round(widthOrLength, MidpointRounding.AwayFromZero) + Math.Round(orderHeight, MidpointRounding.AwayFromZero));
if (girth < 16)
{
Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Girth < 16 (sizes should be in cm)");
return methods;
}
if (girth > 140)
{
Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Girth > 140 (sizes should be in cm)");
return methods;
}
var orderLengthCulture = decimal.Parse(orderLength.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU"));
if (orderInfo.CustomerInfo.CountryCode.ToUpper() == "AU")
{
request.ShippingUrlBase = helper.Settings["ServiceUrlDomestic"];
request.Parameters.Add("from_postcode", postalCodeFrom);
request.Parameters.Add("to_postcode", customerPostalCode);
request.Parameters.Add("length", Math.Round(orderLengthCulture, 2).ToString());
request.Parameters.Add("width", Math.Round(orderWidthCulture, 2).ToString());
request.Parameters.Add("height", Math.Round(orderHeightCulture, 2).ToString());
}
else
{
request.ShippingUrlBase = helper.Settings["ServiceUrlInternational"];
request.Parameters.Add("country_code", orderInfo.CustomerInfo.CountryCode);
}
request.Parameters.Add("weight", Math.Round(orderWeightCulture, 2).ToString());
var requestHeader = new WebHeaderCollection {{"AUTH-KEY", helper.Settings["authKey"]}};
Log.Instance.LogDebug("AUSPOST API URL: " + request.ShippingUrlBase);
Log.Instance.LogDebug("AUSPOST API ParametersAsString: " + request.ParametersAsString);
Log.Instance.LogDebug("AUSPOST API requestHeader AUTH-KEY: " + requestHeader.GetValues("AUTH-KEY"));
var issuerRequest = _requestSender.GetRequest(request.ShippingUrlBase, request.ParametersAsString, requestHeader);
XNamespace ns = string.Empty;
var issuerXml = XDocument.Parse(issuerRequest);
foreach (var service in issuerXml.Descendants(ns + "service"))
{
var issuerId = service.Descendants(ns + "code").First().Value;
var issuerName = service.Descendants(ns + "name").First().Value;
var issuerPriceValue = service.Descendants(ns + "price").First().Value;
decimal issuerPrice;
decimal.TryParse(issuerPriceValue, out issuerPrice);
var priceInCents = issuerPrice*100;
var paymentImageId = 0;
var logoDictionaryItem = library.GetDictionaryItem(issuerId + "LogoId");
if (string.IsNullOrEmpty(logoDictionaryItem))
{
int.TryParse(library.GetDictionaryItem(issuerId + "LogoId"), out paymentImageId);
}
methods.Add(new ShippingProviderMethod {Id = issuerId, Description = issuerName, Title = issuerName, Name = issuerName, ProviderName = GetName(), ImageId = paymentImageId, PriceInCents = (int) priceInCents, Vat = 21});
}
return methods;
}
示例12: GetValues
public void GetValues ()
{
WebHeaderCollection w = new WebHeaderCollection ();
w.Add ("Hello", "H1");
w.Add ("Hello", "H2");
w.Add ("Hello", "H3,H4");
string [] sa = w.GetValues ("Hello");
Assert.AreEqual (3, sa.Length, "#1");
Assert.AreEqual ("H1,H2,H3,H4", w.Get ("Hello"), "#2");
w = new WebHeaderCollection ();
w.Add ("Accept", "H1");
w.Add ("Accept", "H2");
w.Add ("Accept", "H3, H4 ");
Assert.AreEqual (3, w.GetValues (0).Length, "#3a");
Assert.AreEqual (4, w.GetValues ("Accept").Length, "#3b");
Assert.AreEqual ("H4", w.GetValues ("Accept")[3], "#3c");
Assert.AreEqual ("H1,H2,H3, H4", w.Get ("Accept"), "#4");
w = new WebHeaderCollection ();
w.Add ("Allow", "H1");
w.Add ("Allow", "H2");
w.Add ("Allow", "H3,H4");
sa = w.GetValues ("Allow");
Assert.AreEqual (4, sa.Length, "#5");
Assert.AreEqual ("H1,H2,H3,H4", w.Get ("Allow"), "#6");
w = new WebHeaderCollection ();
w.Add ("AUTHorization", "H1, H2, H3");
sa = w.GetValues ("authorization");
Assert.AreEqual (3, sa.Length, "#9");
w = new WebHeaderCollection ();
w.Add ("proxy-authenticate", "H1, H2, H3");
sa = w.GetValues ("Proxy-Authenticate");
Assert.AreEqual (3, sa.Length, "#9");
w = new WebHeaderCollection ();
w.Add ("expect", "H1,\tH2, H3 ");
sa = w.GetValues ("EXPECT");
Assert.AreEqual (3, sa.Length, "#10");
Assert.AreEqual ("H2", sa [1], "#11");
Assert.AreEqual ("H3", sa [2], "#12");
try {
w.GetValues (null);
Assert.Fail ("#13");
} catch (ArgumentNullException) { }
Assert.AreEqual (null, w.GetValues (""), "#14");
Assert.AreEqual (null, w.GetValues ("NotExistent"), "#15");
w = new WebHeaderCollection ();
w.Add ("Accept", null);
Assert.AreEqual (1, w.GetValues ("Accept").Length, "#16");
w = new WebHeaderCollection ();
w.Add ("Accept", ",,,");
Assert.AreEqual (3, w.GetValues ("Accept").Length, "#17");
}
示例13: GetValues_Success
public void GetValues_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("Accept", "text/plain, text/html");
string[] values = w.GetValues("Accept");
Assert.Equal(2, values.Length);
Assert.Equal("text/plain", values[0]);
Assert.Equal("text/html", values[1]);
}
示例14: ParseMachineName
public static string ParseMachineName(WebHeaderCollection responseHeaders)
{
string machineName = "?";
for (int i = 0; i < responseHeaders.Count; i++)
{
if (responseHeaders.Keys[i] == "X-ServerName")
{
string[] values = responseHeaders.GetValues(i);
if (values != null && values.Length > 0) machineName = values[0];
break;
}
}
return machineName;
}
示例15: GetHeader
public override string GetHeader(WebHeaderCollection headers, string name, Func<string, bool> valuePredicate)
{
var values = headers.GetValues(name);
return values == null ? null : values.FirstOrDefault(valuePredicate);
}