HttpListenerResponse.Headers Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the collection of header name/value pairs returned by the 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
A WebHeaderCollection instance that contains all the explicitly set HTTP headers to be included in the response.
The WebHeaderCollection instance specified for a set operation is not valid for a response.
The following code example demonstrates displaying the headers in a 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
Response headers contain metadata information such as the date and time of the response, the identity of the responding server, and the MIME type of the data contained in the response body.
For a complete list of response headers, see the HttpResponseHeader enumeration.
Σημείωση
If you attempt to set a Content-Length, Keep-Alive, Transfer-Encoding, or WWW-Authenticate header using the Headers property, an exception will be thrown. Use the KeepAlive or ContentLength64 properties to set these headers. You cannot set the Transfer-Encoding or WWW-Authenticate headers manually.
Προϊόν | Εκδόσεις |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET σχόλια
.NET είναι ένα έργο ανοιχτού κώδικα. Επιλέξτε μια σύνδεση για να παρέχετε σχόλια: