在ASP Web API
中,升级到WebSocket
需要初始化Microsoft.Web.WebSockets.WebSocketHandler。这种类型的WebSocket
没有提供添加SecWebSocketProtocol标头的选项,这对我的情况很重要(MQTT
超过WebSockets
)。
public HttpResponseMessage Get()
{
if (HttpContext.Current.IsWebSocketRequest || HttpContext.Current.IsWebSocketRequestUpgrading)
{
HttpContext.Current.AcceptWebSocketRequest(new WebSocketHandler());
return Request.CreateResponse(HttpStatusCode.SwitchingProtocols);
}
else return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
如何将此字段添加到WebSocketHandler?