增加用户自定义头信息功能,Header信息
This commit is contained in:
@@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
|
|||||||
//通过使用 "*",如下所示:
|
//通过使用 "*",如下所示:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.1.3")]
|
[assembly: AssemblyVersion("1.0.1.3")]
|
||||||
[assembly: AssemblyFileVersion("1.0.1.5")]
|
[assembly: AssemblyFileVersion("1.0.1.6")]
|
||||||
|
|||||||
@@ -113,6 +113,31 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
_webSocket?.Close();
|
_webSocket?.Close();
|
||||||
_webSocket = new WebSocketSharp.WebSocket(_config.WsUrl);
|
_webSocket = new WebSocketSharp.WebSocket(_config.WsUrl);
|
||||||
|
|
||||||
|
// 设置User-Agent
|
||||||
|
if (!string.IsNullOrEmpty(_config.UserAgent))
|
||||||
|
{
|
||||||
|
_webSocket.Origin = _config.UserAgent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置自定义头信息
|
||||||
|
// WebSocketSharp库的WebSocket类可能没有SetHeader方法,这里暂时注释掉
|
||||||
|
// 后续可以考虑使用其他方式实现自定义头信息的传递
|
||||||
|
if (_config.CustomHeaders != null && _config.CustomHeaders.Count > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// WebSocketSharp库的WebSocket类使用SetHeader方法设置自定义头信息
|
||||||
|
foreach (var header in _config.CustomHeaders)
|
||||||
|
{
|
||||||
|
_webSocket.SetUserHeader(header.Key, header.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 忽略错误
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 设置事件处理
|
// 设置事件处理
|
||||||
_webSocket.OnOpen += WebSocket_OnOpen;
|
_webSocket.OnOpen += WebSocket_OnOpen;
|
||||||
_webSocket.OnMessage += WebSocket_OnMessage;
|
_webSocket.OnMessage += WebSocket_OnMessage;
|
||||||
|
|||||||
@@ -46,5 +46,15 @@ namespace JoyD.Windows.CS.WebSocket
|
|||||||
/// 消息队列最大大小
|
/// 消息队列最大大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaxQueueSize { get; set; } = 100;
|
public int MaxQueueSize { get; set; } = 100;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// User-Agent头
|
||||||
|
/// </summary>
|
||||||
|
public string UserAgent { get; set; } = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义头信息
|
||||||
|
/// </summary>
|
||||||
|
public System.Collections.Generic.Dictionary<string, string> CustomHeaders { get; set; } = new System.Collections.Generic.Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user