如何在 Java Websocket 客户端中添加标头
2022-09-04 01:31:58
我正在使用类连接到Java中的websocket服务器。javax.websocket
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;
public class WSClient {
private WebSocketContainer webSocketContainer;
public void sendMessage(URI endpointURI, String message) throws IOException, DeploymentException {
Session session = webSocketContainer.connectToServer(MyClientEndpoint.class, endpointURI);
session.getAsyncRemote().sendText(message);
}
}
对于初始HTTP握手,我想向客户端的请求添加额外的HTTP标头
这可能吗?
我知道这在服务器端是可能的。客户端是否有类似的解决方案?ServerEndpointConfig.Configurator.modifyHandshake