مشاركة عبر


HttpChallengeHeaderValueCollection Class

Definition

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

public ref class HttpChallengeHeaderValueCollection sealed : IIterable<HttpChallengeHeaderValue ^>, IVector<HttpChallengeHeaderValue ^>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpChallengeHeaderValueCollection final : IIterable<HttpChallengeHeaderValue>, IVector<HttpChallengeHeaderValue>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpChallengeHeaderValueCollection final : IIterable<HttpChallengeHeaderValue>, IVector<HttpChallengeHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpChallengeHeaderValueCollection : IEnumerable<HttpChallengeHeaderValue>, IList<HttpChallengeHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpChallengeHeaderValueCollection : IEnumerable<HttpChallengeHeaderValue>, IList<HttpChallengeHeaderValue>, IStringable
Public NotInheritable Class HttpChallengeHeaderValueCollection
Implements IEnumerable(Of HttpChallengeHeaderValue), IList(Of HttpChallengeHeaderValue), IStringable
Inheritance
Object Platform::Object IInspectable HttpChallengeHeaderValueCollection
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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());
        }

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.

Properties

Size

Gets the number of HttpChallengeHeaderValue objects in the collection.

Methods

Append(HttpChallengeHeaderValue)

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

Clear()

Removes all HttpChallengeHeaderValue objects from the collection.

First()

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

GetAt(UInt32)

Returns the HttpChallengeHeaderValue at the specified index in the collection.

GetMany(UInt32, HttpChallengeHeaderValue[])

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

GetView()

Returns an immutable view of the HttpChallengeHeaderValueCollection.

IndexOf(HttpChallengeHeaderValue, UInt32)

Retrieves the index of an HttpChallengeHeaderValue in the collection.

InsertAt(UInt32, HttpChallengeHeaderValue)

Inserts an HttpChallengeHeaderValue into the collection at the specified index.

ParseAdd(String)

Parses and adds an entry to the HttpChallengeHeaderValueCollection.

RemoveAt(UInt32)

Removes the entry at the specified index from the HttpChallengeHeaderValueCollection.

RemoveAtEnd()

Removes the last HttpChallengeHeaderValue item from the collection.

ReplaceAll(HttpChallengeHeaderValue[])

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

SetAt(UInt32, HttpChallengeHeaderValue)

Sets the HttpChallengeHeaderValue at the specified index in the collection.

ToString()

Returns a string that represents the current HttpChallengeHeaderValueCollection object.

TryParseAdd(String)

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

Applies to

See also