websocket-sharp-customheaders发送标头

我已经为我的WebSocket应用程序安装了nuget软件包websocket-sharp-customheaders,并希望在http-header-information中发送sessionId。 客户代码:

public class SocketController
{
    public static readonly string ConnectionString = "ws://localhost:{0}/{1}";

    private string sessionId;

    public WebSocket NotificationSocket { get; private set; }

    public SocketController(ServiceConfiguration config)
    {
        NotificationSocket = new WebSocket(string.Format(ConnectionString,config.Port,"Notify"));
    }

    public void Connect()
    {
        NotificationSocket.Connect();
    }

    public void SendNotification(string sessionId,Notification data)
    {
        if (NotificationSocket.ReadyState == WebSocketState.Open)
        {
            NotificationSocket.CustomHeaders = new Dictionary<string,string> { { "SessionId",sessionId } };
            NotificationSocket.Send(data.SerializeJson());
        }
    }

    public void SetNotificationSocketOnmessage(action<NotifyMessage> onmessage)
    {
        NotificationSocket.Onmessage += (sender,e) => onmessage(e.Data.DeserializeJson<NotifyMessage>());
    }

    public void Stop()
    {
        NotificationSocket.Close();
    }
}

在SendNotification中设置头。但是服务器未收到标头信息。

服务器套接字行为:

    public class NotifyService : WebSocketBehavior
    {
        protected override void Onmessage(MessageEventArgs e)
        {
            var command = e.Data;

            if (!Context.Headers.Contains("SessionId"))
                return;

            // Stuff todo with SessionId and Data
        }
    }

有人可以告诉我如何正确发送标头信息吗?

iamhero3333 回答:websocket-sharp-customheaders发送标头

https://github.com/sta/websocket-sharp/pull/22

我相信他们不允许这样做。

本文链接:https://www.f2er.com/3138861.html

大家都在问