在.NET 4.5中设置Websocket握手的自定义标头 [英] Set custom headers for websocket handshake in .NET 4.5

查看:266
本文介绍了在.NET 4.5中设置Websocket握手的自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置C#客户端与第三方服务器的WebSocket连接.当我用JS客户端连接到同一台服务器时,它建立了连接,一切正常. C#客户端连接到服务器,但是由于某些未知原因,服务器以500个代码响应.使用WireShark进行的调试表明,在一组标头中,客户端实现之间WebSocket连接的HTTP握手阶段有所不同.我想调整默认的System.Net.WebSockets.ClientWebSocket类头发送到服务器,以检查问题是否存在.不过,我找不到办法.

I'm trying to set a WebSocket connection of C# client with third-party server. When I connect with JS client to the same server, it establishes connection and everything goes fine. C# client connects to the server, but for some unknown reason server responds with 500 code. Debugging with WireShark has shown that HTTP handshake phase of WebSocket connection differs between client implementation in a set of headers. I would like to tweak the headers default System.Net.WebSockets.ClientWebSocket class sends to the server to check that the issue is there. Though, I couldn't find a way to do that.

如何指示该命名空间中其他类的ClientWebSocket在握手阶段发送其他给定的标头?

How do I instruct ClientWebSocket of some other class in that namespace to send additional given headers in handshake phase?

推荐答案

它似乎由ClientWebSocketOptions.SetRequestHeader公开,所以:

obj.Options.SetRequestHeader("foo", "bar");

应该工作.这也提供对AddSubProtocol(...)的访问.

should work. This also provides access to AddSubProtocol(...).

这篇关于在.NET 4.5中设置Websocket握手的自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆