I am trying to connect (with windows form application) to a socket which use sec-websocket-protocol
for authentication . in browser everything is OK but when i try to simulate that connection with c# it fails with error Includes no Sec-WebSocket-Protocol header, or it has an invalid value.
. Log file :
20/11/2020 6:24:55 PM|Debug|WebSocket.sendHttpRequest:0|A request to the server:
GET /?encoding=text HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0
Host: ------.com
Upgrade: websocket
Connection: keep-alive, Upgrade
Sec-WebSocket-Key: M3Ce------tUGg==
Sec-WebSocket-Version: 13
Accept: * / *
Accept-Encoding: gzip, deflate, br
Accept-Language: el-GR,el;q=0.9,en;q=0.8
Cache-Control: no-cache
Origin: https://--------.com
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Protocol: 549b4ftghj423f4a26------------------
20/11/2020 6:24:55 PM|Debug|WebSocket.sendHttpRequest:0|A response to this request:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: J2344x5eH------
Sec-WebSocket-Protocol: 549b4ftghj423f4a26----------------
20/11/2020 6:24:55 PM|Fatal|WebSocket.connect:0|WebSocketSharp.WebSocketException: Includes no Sec-WebSocket-Protocol header, or it has an invalid value.
at WebSocketSharp.WebSocket.doHandshake()
at WebSocketSharp.WebSocket.connect()
20/11/2020 6:24:55 PM|Debug|WebSocket.closeHandshake:0|Was clean?: False
sent: False
received: False
Sec-WebSocket-Protocol
value is a code that i get from another API
.and i think i get the value correctly from the api . i checked that over times .
and this is my c# Code :
ws2 = new WebSocket("wss://" + "---------.com" + "/?encoding=text");
ws2.Log.Level = LogLevel.Debug;
ws2.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
ws2.CustomHeaders = new Dictionary<string, string>
{
{ "Accept", "*/*" },
{ "Accept-Encoding", "gzip, deflate, br" },
{ "Accept-Language", "el-GR,el;q=0.9,en;q=0.8" },
{ "Cache-Control", "no-cache" },
{ "Connection", "keep-alive, Upgrade" },
{ "Origin", "https://---------.com" },
{ "Pragma", "no-cache" },
{ "Sec-WebSocket-Protocol", "549b4ftghj423f4a26------------------" },
{ "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" }
};
ws2.Origin = "https://---------.com" ;
ws2.OnOpen += (sender, e) =>
{
ConsoleWriteLine("OnOpen");
};
ws2.OnError += (sender, e) =>
{
ConsoleWriteLine("OnError: " + e.Message);
};
ws2.OnClose += (sender, e) =>
{
ConsoleWriteLine("OnClose");
};
ws2.OnMessage += (sender, e) =>
ConsoleWriteLine("Laputa says: " + e.Data);
ws2.Connect();
is it possible Sec-WebSocket-Protocol
value changes by seting wrong SslConfiguration
. ( i am not sure that i should use System.Security.Authentication.SslProtocols.Tls12
) ?
i tried :
1- deleting Sec-WebSocket-Protocol
from header --> response error : HEADER_AUTH_WS or HEADER_WEB_SOCKET_SUB_PROTOCOL is empty
2- deleting line that sets SslConfiguration.EnabledSslProtocols
--> nothing changed.