本文整理汇总了C#中WebHeaderCollection.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# WebHeaderCollection.GetValues方法的具体用法?C# WebHeaderCollection.GetValues怎么用?C# WebHeaderCollection.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebHeaderCollection
的用法示例。
在下文中一共展示了WebHeaderCollection.GetValues方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HttpRequestHeader_Get_Success
public void HttpRequestHeader_Get_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
w.Add("header1", "value2");
string[] values = w.GetValues(0);
Assert.Equal("value1", values[0]);
Assert.Equal("value2", values[1]);
}
示例2: GetValues_Int_Fail
public void GetValues_Int_Fail()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("Accept", "text/plain");
Assert.Throws<ArgumentOutOfRangeException>(() => w.GetValues(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => w.GetValues(42));
}
示例3: GetValues_Int_Success
public void GetValues_Int_Success()
{
string[] keys = { "Accept", "uPgRaDe", "Custom" };
string[] values = { "text/plain, text/html", " HTTP/2.0 , SHTTP/1.3, , RTA/x11 ", "\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\"" };
WebHeaderCollection w = new WebHeaderCollection();
for (int i = 0; i < keys.Length; ++i)
{
w.Add(keys[i], values[i]);
}
for (int i = 0; i < keys.Length; ++i)
{
string[] expected = new[] { values[i].Trim() };
Assert.Equal(expected, w.GetValues(i));
}
}
示例4: GetValues_String_Success
public void GetValues_String_Success(string header, string value, string[] expectedValues)
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add(header, value);
string modifiedHeader = header.ToLowerInvariant(); // header should be case insensitive
Assert.Equal(expectedValues, w.GetValues(modifiedHeader));
}
示例5: GetNonExistent_ReturnsNull_Success
public void GetNonExistent_ReturnsNull_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
Assert.Equal(0, w.Count);
Assert.Null(w["name"]);
Assert.Null(w.GetValues("name"));
}
示例6: HttpRequestHeader_GetValues_Success
public void HttpRequestHeader_GetValues_Success()
{
WebHeaderCollection w = new WebHeaderCollection();
w.Add("header1", "value1");
Assert.Equal("value1", w.GetValues("header1")[0]);
}
示例7: AddHeaderValues
private static void AddHeaderValues(WebHeaderCollection source, int index, string header, HttpHeaders destination)
{
string[] values = source.GetValues(index);
// Even though AddWithoutValidation() could throw FormatException for header values containing newline
// chars that are not followed by whitespace chars, we don't need to catch that exception. Our header
// values were returned by HttpWebResponse which is trusted to only return valid header values.
if (values.Length == 1)
{
destination.AddWithoutValidation(header, values[0]);
}
else
{
for (int j = 0; j < values.Length; j++)
{
destination.AddWithoutValidation(header, values[j]);
}
}
}
示例8: TestWebHeaderCollectionGetValues
public void TestWebHeaderCollectionGetValues()
{
WebHeaderCollection whc = new WebHeaderCollection();
string[] strArray1;
try
{
strArray1 = whc.GetValues(null);
Fail("GetValues: failed to throw exception for null argument");
}
catch(ArgumentNullException)
{
// Ok
}
whc.Add("phony:junk");
whc.Add("more", "stuff");
string[] strArray = whc.GetValues("phony");
if (strArray[0] != "junk")
Fail("GetValues: returned incorrect data for 'phony:junk'");
strArray1 = whc.GetValues("more");
if (strArray1[0] != "stuff")
Fail("GetValues: returned incorrect data for 'more:stuff'");
string[] strArray2 = whc.GetValues("notThere");
if (strArray2 != null)
Fail("GetValues: did not return null for name:value not in collection");
}