HttpResponseHeaderCollection.ProxyAuthenticate 属性

定义

获取 HttpChallengeHeaderValue 对象的 HttpChallengeHeaderValueCollection ,这些对象表示 HTTP 响应上的 代理身份验证 HTTP 标头的值。

public:
 property HttpChallengeHeaderValueCollection ^ ProxyAuthenticate { HttpChallengeHeaderValueCollection ^ get(); };
HttpChallengeHeaderValueCollection ProxyAuthenticate();
public HttpChallengeHeaderValueCollection ProxyAuthenticate { get; }
var httpChallengeHeaderValueCollection = httpResponseHeaderCollection.proxyAuthenticate;
Public ReadOnly Property ProxyAuthenticate As HttpChallengeHeaderValueCollection

属性值

HttpChallengeHeaderValue 对象的集合,这些对象表示 HTTP 响应上的代理身份验证 HTTP 标头的值。 空集合表示标头不存在。

注解

以下示例代码演示了一种方法,该方法使用 HttpResponseHeaderCollection 对象的 ProxyAuthenticate 属性在 HttpResponseMessage 对象上获取和设置 Proxy-Authenticate 标头。

// Proxy-Authenticate: Basic
// HttpChallengeHeaderValueCollection
// HttpChallengeHeaderValue has Scheme and Token (both strings) + Parameters
// Parameters is an IList<HttpNameValueHeaderValue>
// HttpNameValueHeaderValue has Name and Value, both strings
    void DemoProxyAuthenticate(HttpResponseMessage response) {
        var h = response.Headers;
        h.ProxyAuthenticate.TryParseAdd("Basic");
        h.ProxyAuthenticate.Add(new HttpChallengeHeaderValue("digest", "token"));

        var header = h.ProxyAuthenticate;
        uiLog.Text += "\nPROXY AUTHENTICATE HEADER\n";
        foreach (var item in header) {
            // Parameters is an IList<HttpNameValueHeaderValue> of Name/Value strings
            var parameterString = "";
            foreach (var parameter in item.Parameters) {
                parameterString += string.Format("[{0}={1}] ", parameter.Name, parameter.Value);
            }
            if (parameterString == "") {
                parameterString = "(no parameters)";
            }
            uiLog.Text += string.Format("Scheme: {0} Token: {1} Parameters: {2} ToString(): {3}\n", item.Scheme, item.Token, parameterString, item.ToString());
        }
        uiLog.Text += String.Format("ProxyAuthenticate: {0}\n", header.ToString());
    }

适用于

另请参阅