The obvious answer of using ClientWebSocket.SetHeader
throws an exception because it's a protected header:
System.ArgumentException occurred Message=The 'User-Agent' header must be modified using the appropriate property or method. Parameter name: name ParamName=name StackTrace: at System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String headerName)
The exception string suggests using a property/method on the ClientWebSocket
itself but I can't find any such property/method. It seems this exception was designed for the HttpWebRequest
class, which actually has such property.
The code, which doesn't work:
ClientWebSocket socket = new ClientWebSocket();
// Will throw
socket.Options.SetRequestHeader("User-Agent", "SomeUserAgentString");
// Will throw
socket.Options.SetRequestHeader("Referer", "SomeReferer"]);