问题
How To Send Request Header To Jetty WebSocket From JavaScript Client ?
What I am doing ?
At Client Side.
- Need To add service name and service version in request header at client side
- Send to server
At Server Side.
- Identify the service from the request header
- Using that create corresponding input translator (using GSON)
- Create service input using that translator
- Call the service.
I can use org.eclipse.jetty.websocket.api.annotations.WebSocket as to get service name and version at server side. But..... How can I set the header information at client side?
@OnWebSocketMessage
public void onText(Session session, String message) {
if (session.isOpen()) {
System.out.println(session.getUpgradeRequest().getHeader("service"));
System.out.println(session.getUpgradeRequest().getHeader("version"));
System.out.printf("Echoing back message [%s]%n", message);
session.getRemote().sendString(message, null);
}
}
Thanks for your support...
回答1:
Unfortunately, you can't. The standard WebSocket JavaScript API does not provide means to customize HTTP headers. See also this document at heroku dev center.
来源:https://stackoverflow.com/questions/29844804/how-to-send-request-header-to-jetty-websocket-from-javascript-client