共用方式為


HttpListenerRequest.KeepAlive 屬性

定義

取得 Boolean 值,指出用戶端是否要求持續性連線。

public:
 property bool KeepAlive { bool get(); };
public bool KeepAlive { get; }
member this.KeepAlive : bool
Public ReadOnly Property KeepAlive As Boolean

屬性值

如果連線應該保持開啟,則為 true,否則為 false

範例

下列程式代碼範例示範如何使用這個屬性。

public static void ShowRequestProperties2 (HttpListenerRequest request)
{
    Console.WriteLine("KeepAlive: {0}", request.KeepAlive);
    Console.WriteLine("Local end point: {0}", request.LocalEndPoint.ToString());
    Console.WriteLine("Remote end point: {0}", request.RemoteEndPoint.ToString());
    Console.WriteLine("Is local? {0}", request.IsLocal);
    Console.WriteLine("HTTP method: {0}", request.HttpMethod);
    Console.WriteLine("Protocol version: {0}", request.ProtocolVersion);
    Console.WriteLine("Is authenticated: {0}", request.IsAuthenticated);
    Console.WriteLine("Is secure: {0}", request.IsSecureConnection);
}
Public Shared Sub ShowRequestProperties2(ByVal request As HttpListenerRequest)
    Console.WriteLine("KeepAlive: {0}", request.KeepAlive)
    Console.WriteLine("Local end point: {0}", request.LocalEndPoint.ToString())
    Console.WriteLine("Remote end point: {0}", request.RemoteEndPoint.ToString())
    Console.WriteLine("Is local? {0}", request.IsLocal)
    Console.WriteLine("HTTP method: {0}", request.HttpMethod)
    Console.WriteLine("Protocol version: {0}", request.ProtocolVersion)
    Console.WriteLine("Is authenticated: {0}", request.IsAuthenticated)
    Console.WriteLine("Is secure: {0}", request.IsSecureConnection)
End Sub

備註

如果 HTTP 用戶端和伺服器預期在短時間內交換數據多次,持續性聯機會允許它們避免開啟和關閉每個訊息的 TCP 連線所需的額外負荷,以加速其通訊。 對於使用 HTTP/1.1 的用戶端,此屬性的預設值為 true

適用於

另請參閱