-api-id | -api-type |
---|---|
T:Windows.Web.Http.Headers.HttpChallengeHeaderValueCollection |
winrt class |
Represents the value of the Proxy-Authenticate or WWW-Authenticate HTTP header on an HTTP response.
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.
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.
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.
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());
}
HttpChallengeHeaderValue, HttpResponseMessage, HttpResponseHeaderCollection, IIterable(HttpChallengeHeaderValue), IStringable, IVector(HttpChallengeHeaderValue), ProxyAuthenticate, WwwAuthenticate