var websocket = new WebSocket('ws://example.com/server'); websocket.onopen = function() { console.log('WebSocket连接成功!'); websocket.send('Hello, AdBlock!'); };
var websocket = new WebSocket('ws://example.com/server', ['my-custom-header']); websocket.onopen = function() { console.log('WebSocket连接成功!'); websocket.send('Hello, AdBlock!'); };
然后,在服务器端响应请求时添加自定义HTTP头部:
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade My-Custom-Header: true