天道酬勤,学无止境

system.net.websockets

在 ClientWebSocket 中设置“User-Agent”HTTP 标头(Setting “User-Agent” HTTP header in ClientWebSocket)

问题 我需要在ClientWebSocket对象中设置“User-Agent”HTTP 标头,但这是不可能的。 尽管有ClientWebSocket.SetRequestHeader(header,value) ,但如果我尝试设置该标头,该方法将失败: System.ArgumentException: This header must be modified using the appropriate property or method. 查看ClientWebSocket源代码,似乎MS人完全忘记了这一点: // System.Net.WebSockets.ClientWebSocket private HttpWebRequest CreateAndConfigureRequest(Uri uri) { HttpWebRequest httpWebRequest = WebRequest.Create(uri) as HttpWebRequest; if (httpWebRequest == null) { throw new InvalidOperationException(SR.GetString("net_WebSockets_InvalidRegistration")); } foreach (string name in this.options

2021-06-11 18:02:01    分类:技术分享    .net   websocket   clientwebsocket   system.net.websockets