HttpListenerRequest.KeepAlive 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 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
。