HttpChallengeHeaderValueCollection HttpChallengeHeaderValueCollection HttpChallengeHeaderValueCollection HttpChallengeHeaderValueCollection Class

Definition

Represents the value of the Proxy-Authenticate or WWW-Authenticate HTTP header on an HTTP response.

public sealed class HttpChallengeHeaderValueCollectionpublic sealed class HttpChallengeHeaderValueCollectionPublic NotInheritable Class HttpChallengeHeaderValueCollectionpublic sealed class HttpChallengeHeaderValueCollection
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The HttpChallengeHeaderValueCollection represents the value of the Proxy-Authenticate or WWW-Authenticate HTTP header on an HTTP response.

The HttpChallengeHeaderValueCollection provides a collection container for instances of the HttpChallengeHeaderValue class used for authentication information used in the Authorization, ProxyAuthorization, WWW-Authenticate, and Proxy-Authenticate HTTP header values.

The ProxyAuthenticate property on HttpResponseHeaderCollection returns an HttpChallengeHeaderValueCollection object. The WwwAuthenticate property on HttpResponseHeaderCollection also returns an HttpChallengeHeaderValueCollection object.

Collection member lists

For JavaScript, HttpChallengeHeaderValueCollection has the members shown in the member lists. In addition, HttpChallengeHeaderValueCollection supports members of Array.prototype and using an index to access items.

Enumerating the collection in C# or Microsoft Visual Basic

You can iterate through an HttpChallengeHeaderValueCollection object in C# or Microsoft Visual Basic. In many cases, such as using foreach syntax, the compiler does this casting for you and you won't need to cast to IEnumerable<HttpChallengeHeaderValue> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast the collection object to IEnumerable<T> with an HttpChallengeHeaderValue constraint.

Examples

The following sample code shows a method to get and set the Proxy-Authenticate HTTP header on an HttpResponseMessage object using the properties and methods on the HttpChallengeHeaderValueCollection and HttpChallengeHeaderValue classes.

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        public void DemonstrateHeaderResponseProxyAuthenticate() {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.ProxyAuthenticate.TryParseAdd("Basic");
            response.Headers.ProxyAuthenticate.Add(new HttpChallengeHeaderValue("authScheme", "authToken"));

            // Get the strong type out
            foreach (var value in response.Headers.ProxyAuthenticate) {
                System.Diagnostics.Debug.WriteLine("Proxy authenticate scheme and token: {0} {1}", value.Scheme, value.Token);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The ProxyAuthenticate ToString() results: {0}", response.Headers.ProxyAuthenticate.ToString());
        }

Properties

Size Size Size Size

Gets the number of HttpChallengeHeaderValue objects in the collection.

public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uintpublic uint Size { get; }
Value
uint uint uint uint

The number of HttpChallengeHeaderValue objects in the HttpChallengeHeaderValueCollection.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The Size value returns the true number of items. API that use the index, such as IndexOf(HttpChallengeHeaderValue, UInt32), use a zero-based index, so you would subtract one from Size in order to specify that you want the last item in the collection.

If you are programming using C# or Microsoft Visual Basic, the equivalent method is Count.

Methods

Append(HttpChallengeHeaderValue) Append(HttpChallengeHeaderValue) Append(HttpChallengeHeaderValue) Append(HttpChallengeHeaderValue)

Adds a new HttpChallengeHeaderValue item to the end of the collection.

public void Append(HttpChallengeHeaderValue value)public void Append(HttpChallengeHeaderValue value)Public Function Append(value As HttpChallengeHeaderValue) As voidpublic void Append(HttpChallengeHeaderValue value)
Parameters
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

After you've added an item, you can use the IndexOf(HttpChallengeHeaderValue, UInt32) method to get it by index.

To add an item to a position in the collection that's not at the collection end, use the InsertAt(UInt32, HttpChallengeHeaderValue) method.

If you are programming using C# or Microsoft Visual Basic, the equivalent method is Add.

Clear() Clear() Clear() Clear()

Removes all HttpChallengeHeaderValue objects from the collection.

public void Clear()public void Clear()Public Function Clear() As voidpublic void Clear()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

First() First() First() First()

Retrieves an iterator to the first HttpChallengeHeaderValue item in the collection.

public IIterator<HttpChallengeHeaderValue> First()public IIterator<HttpChallengeHeaderValue> First()Public Function First() As IIterator( Of HttpChallengeHeaderValue )public IIterator<HttpChallengeHeaderValue> First()
Returns

An object that can be used to enumerate the HttpChallengeHeaderValue items in the collection. The iterator points to the first HttpChallengeHeaderValue item in the HttpChallengeHeaderValueCollection.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

GetAt(UInt32) GetAt(UInt32) GetAt(UInt32) GetAt(UInt32)

Returns the HttpChallengeHeaderValue at the specified index in the collection.

public HttpChallengeHeaderValue GetAt(UInt32 index)public HttpChallengeHeaderValue GetAt(UInt32 index)Public Function GetAt(index As UInt32) As HttpChallengeHeaderValuepublic HttpChallengeHeaderValue GetAt(UInt32 index)
Parameters
index
System.UInt32 System.UInt32 System.UInt32 System.UInt32

The zero-based index of a specified item in the HttpChallengeHeaderValueCollection.

Returns
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

If you are programming using C# or Microsoft Visual Basic, the equivalent method is Item for the GetAt(UInt32) and SetAt(UInt32, HttpChallengeHeaderValue) methods.

GetMany(UInt32, HttpChallengeHeaderValue[]) GetMany(UInt32, HttpChallengeHeaderValue[]) GetMany(UInt32, HttpChallengeHeaderValue[]) GetMany(UInt32, HttpChallengeHeaderValue[])

Retrieves the HttpChallengeHeaderValue items that start at the specified index in the collection.

public uint GetMany(UInt32 startIndex, HttpChallengeHeaderValue[] items)public uint GetMany(UInt32 startIndex, HttpChallengeHeaderValue[] items)Public Function GetMany(startIndex As UInt32, items As HttpChallengeHeaderValue[]) As uintpublic uint GetMany(UInt32 startIndex, HttpChallengeHeaderValue[] items)
Parameters
startIndex
System.UInt32 System.UInt32 System.UInt32 System.UInt32

The zero-based index of the start of the HttpChallengeHeaderValue items in the HttpChallengeHeaderValueCollection.

items
Windows.Web.Http.Headers.HttpChallengeHeaderValue[] Windows.Web.Http.Headers.HttpChallengeHeaderValue[] Windows.Web.Http.Headers.HttpChallengeHeaderValue[] Windows.Web.Http.Headers.HttpChallengeHeaderValue[]

An array of HttpChallengeHeaderValue items that start at startIndex in the HttpChallengeHeaderValueCollection.

Returns
uint uint uint uint

The number of HttpChallengeHeaderValue items retrieved.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The elements are copied to the array in the same order in which the enumerator iterates through the collection. It's typical to specify startIndex as 0 if all you're doing is making a simple copy of the collection items, where you've created a destination array with a length that matches the Size of the collection you're copying.

This method will throw an exception if the number of elements in the source collection is greater than the length of the destination array specified in items.

If you are programming using Visual C++ component extensions (C++/CX) or JavaScript, CopyTo has similar behavior to GetMany(UInt32, HttpChallengeHeaderValue[]), but note that the parameters are in a different order. Or you can make an IVectorView<T> copy by calling the GetView() method.

GetView() GetView() GetView() GetView()

Returns an immutable view of the HttpChallengeHeaderValueCollection.

public IVectorView<HttpChallengeHeaderValue> GetView()public IVectorView<HttpChallengeHeaderValue> GetView()Public Function GetView() As IVectorView( Of HttpChallengeHeaderValue )public IVectorView<HttpChallengeHeaderValue> GetView()
Returns
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When programming with .NET, this method is hidden.

IndexOf(HttpChallengeHeaderValue, UInt32) IndexOf(HttpChallengeHeaderValue, UInt32) IndexOf(HttpChallengeHeaderValue, UInt32) IndexOf(HttpChallengeHeaderValue, UInt32)

Retrieves the index of an HttpChallengeHeaderValue in the collection.

public bool IndexOf(HttpChallengeHeaderValue value, UInt32 index)public bool IndexOf(HttpChallengeHeaderValue value, UInt32 index)Public Function IndexOf(value As HttpChallengeHeaderValue, index As UInt32) As boolpublic bool IndexOf(HttpChallengeHeaderValue value, UInt32 index)
Parameters
index
System.UInt32 System.UInt32 System.UInt32 System.UInt32

The index of the HttpChallengeHeaderValue in the HttpChallengeHeaderValueCollection.

If the item is found, this is the zero-based index of the item; otherwise, this parameter is 0.

Returns
bool bool bool bool

Indicates whether the item is found.

true if the HttpChallengeHeaderValue item is found; otherwise, false.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

If you are programming using C# or Microsoft Visual Basic, the equivalent method is IndexOf(HttpChallengeHeaderValue, UInt32).

InsertAt(UInt32, HttpChallengeHeaderValue) InsertAt(UInt32, HttpChallengeHeaderValue) InsertAt(UInt32, HttpChallengeHeaderValue) InsertAt(UInt32, HttpChallengeHeaderValue)

Inserts an HttpChallengeHeaderValue into the collection at the specified index.

public void InsertAt(UInt32 index, HttpChallengeHeaderValue value)public void InsertAt(UInt32 index, HttpChallengeHeaderValue value)Public Function InsertAt(index As UInt32, value As HttpChallengeHeaderValue) As voidpublic void InsertAt(UInt32 index, HttpChallengeHeaderValue value)
Parameters
index
System.UInt32 System.UInt32 System.UInt32 System.UInt32

The zero-based index at which value should be inserted.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

To add an item to the end position in the collection, you can use the Append(HttpChallengeHeaderValue) method. Calling InsertAt(UInt32, HttpChallengeHeaderValue) with an index value that is the same as the Size value is equivalent to calling Append(HttpChallengeHeaderValue).

If you are programming using C# or Microsoft Visual Basic, the equivalent method is InsertAt(UInt32, HttpChallengeHeaderValue).

ParseAdd(String) ParseAdd(String) ParseAdd(String) ParseAdd(String)

Parses and adds an entry to the HttpChallengeHeaderValueCollection.

public void ParseAdd(String input)public void ParseAdd(String input)Public Function ParseAdd(input As String) As voidpublic void ParseAdd(String input)
Parameters
input
System.String System.String System.String System.String

The entry to add.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

RemoveAt(UInt32) RemoveAt(UInt32) RemoveAt(UInt32) RemoveAt(UInt32)

Removes the entry at the specified index from the HttpChallengeHeaderValueCollection.

public void RemoveAt(UInt32 index)public void RemoveAt(UInt32 index)Public Function RemoveAt(index As UInt32) As voidpublic void RemoveAt(UInt32 index)
Parameters
index
System.UInt32 System.UInt32 System.UInt32 System.UInt32

The index of the entry to remove.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

If successful, calling this method reduces the collection size by one. Items with index values greater than the called index have their index values reduced by one.

If you are programming using C# or Microsoft Visual Basic, the equivalent method is RemoveAt(UInt32). The behavior of each language's RemoveAt(UInt32) is basically the same.

RemoveAtEnd() RemoveAtEnd() RemoveAtEnd() RemoveAtEnd()

Removes the last HttpChallengeHeaderValue item from the collection.

public void RemoveAtEnd()public void RemoveAtEnd()Public Function RemoveAtEnd() As voidpublic void RemoveAtEnd()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When programming with .NET, this method is hidden and developers should use RemoveAt(UInt32).

ReplaceAll(HttpChallengeHeaderValue[]) ReplaceAll(HttpChallengeHeaderValue[]) ReplaceAll(HttpChallengeHeaderValue[]) ReplaceAll(HttpChallengeHeaderValue[])

Replaces all the HttpChallengeHeaderValue items in the collection with the specified HttpChallengeHeaderValue items.

public void ReplaceAll(HttpChallengeHeaderValue[] items)public void ReplaceAll(HttpChallengeHeaderValue[] items)Public Function ReplaceAll(items As HttpChallengeHeaderValue[]) As voidpublic void ReplaceAll(HttpChallengeHeaderValue[] items)
Parameters
items
Windows.Web.Http.Headers.HttpChallengeHeaderValue[] Windows.Web.Http.Headers.HttpChallengeHeaderValue[] Windows.Web.Http.Headers.HttpChallengeHeaderValue[] Windows.Web.Http.Headers.HttpChallengeHeaderValue[]

The collection of HttpChallengeHeaderValue items to add to the collection.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When programming with .NET, this method is hidden.

SetAt(UInt32, HttpChallengeHeaderValue) SetAt(UInt32, HttpChallengeHeaderValue) SetAt(UInt32, HttpChallengeHeaderValue) SetAt(UInt32, HttpChallengeHeaderValue)

Sets the HttpChallengeHeaderValue at the specified index in the collection.

public void SetAt(UInt32 index, HttpChallengeHeaderValue value)public void SetAt(UInt32 index, HttpChallengeHeaderValue value)Public Function SetAt(index As UInt32, value As HttpChallengeHeaderValue) As voidpublic void SetAt(UInt32 index, HttpChallengeHeaderValue value)
Parameters
index
System.UInt32 System.UInt32 System.UInt32 System.UInt32

The zero-based index at which to set the HttpChallengeHeaderValue.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

If you are programming using C# or Microsoft Visual Basic, the equivalent method is Item for the GetAt(UInt32) and SetAt(UInt32, HttpChallengeHeaderValue) methods.

ToString() ToString() ToString() ToString()

Returns a string that represents the current HttpChallengeHeaderValueCollection object.

public string ToString()public string ToString()Public Function ToString() As stringpublic string ToString()
Returns
string string string string

A string that represents the current object.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

TryParseAdd(String) TryParseAdd(String) TryParseAdd(String) TryParseAdd(String)

Tries to parse and add the specified item to the HttpChallengeHeaderValueCollection.

public bool TryParseAdd(String input)public bool TryParseAdd(String input)Public Function TryParseAdd(input As String) As boolpublic bool TryParseAdd(String input)
Parameters
input
System.String System.String System.String System.String

The item to parse and add.

Returns
bool bool bool bool

true if the item successfully parsed and was added; otherwise false.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)