HttpListenerResponse.Headers Proprietà

Definizione

Ottiene o imposta un insieme di coppie nome/valore di intestazione restituite dal server.

public:
 property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); void set(System::Net::WebHeaderCollection ^ value); };
public System.Net.WebHeaderCollection Headers { get; set; }
member this.Headers : System.Net.WebHeaderCollection with get, set
Public Property Headers As WebHeaderCollection

Valore della proprietà

WebHeaderCollection

Istanza di WebHeaderCollection contenente tutte le intestazioni HTTP impostate in modo esplicito da includere nella risposta.

Eccezioni

L'istanza di WebHeaderCollection specificata per un'operazione di impostazione non è valida per una risposta.

Esempio

Nell'esempio di codice seguente viene illustrata la visualizzazione delle intestazioni in un oggetto WebHeaderCollection.

    // Displays the header information that accompanied a request.
public static void DisplayWebHeaderCollection(HttpListenerResponse response)
{
    WebHeaderCollection headers = response.Headers;
    // Get each header and display each value.
    foreach (string key in headers.AllKeys)
    {
        string[] values = headers.GetValues(key);
        if(values.Length > 0)
        {
            Console.WriteLine("The values of the {0} header are: ", key);
            foreach (string value in values)
            {
                Console.WriteLine("   {0}", value);
            }
        }
        else
        {
            Console.WriteLine("There is no value associated with the header.");
        }
    }
}
' Displays the header information that accompanied a request.
Public Shared Sub DisplayWebHeaderCollection(ByVal response As HttpListenerResponse)
    Dim headers As WebHeaderCollection = response.Headers

    ' Get each header and display each value.
    For Each key As String In headers.AllKeys
        Dim values As String() = headers.GetValues(key)

        If values.Length > 0 Then
            Console.WriteLine("The values of the {0} header are: ", key)

            For Each value As String In values
                Console.WriteLine("   {0}", value)
            Next
        Else
            Console.WriteLine("There is no value associated with the header.")
        End If
    Next
End Sub

Commenti

Le intestazioni di risposta contengono informazioni sui metadati, ad esempio la data e l'ora della risposta, l'identità del server di risposta e il tipo MIME dei dati contenuti nel corpo della risposta.

Per un elenco completo delle intestazioni di risposta, vedere l'enumerazione HttpResponseHeader .

Nota

Se si tenta di impostare un'intestazione Content-Length, Keep-Alive, Transfer-Encoding o WWW-Authenticate utilizzando la proprietà Headers, verrà generata un'eccezione. Usare le KeepAlive proprietà o ContentLength64 per impostare queste intestazioni. Non è possibile impostare manualmente le intestazioni di Transfer-Encoding o di WWW-Authenticate.

Si applica a

Vedi anche