如何将请求 header 添加到 BayeuxClient
How to add request header to BayeuxClient
String url = "some_url";
HttpClient httpClient = new HttpClient();
httpClient.start();
Map<String, Object> options = new HashMap<String, Object>();
LongPollingTransport transport = new LongPollingTransport(options, httpClient);
BayeuxClient client = new BayeuxClient(url, transport);
client.getChannel(Channel.META_HANDSHAKE).addListener(new ClientSessionChannel.MessageListener() {
public void onMessage(ClientSessionChannel channel, Message message) {
System.out.println(message);
}
});
client.handshake();
获得
{"failure":{"exception":"org.cometd.common.TransportException: {httpCode=403}","message":{"supportedConnectionTypes":["long-polling"],"channel":"/meta/handshake","id":"2","version":"1.0"},"httpCode":403,"connectionType":"long-polling"},"channel":"/meta/handshake","id":"2","subscription":null,"successful":false}
所以我的第一个猜测是添加授权header。我怎样才能做到这一点?
Jetty 9 用于服务器和客户端代码库。
请查看显示操作方法的 this test case。
String url = "some_url";
HttpClient httpClient = new HttpClient();
httpClient.start();
Map<String, Object> options = new HashMap<String, Object>();
LongPollingTransport transport = new LongPollingTransport(options, httpClient);
BayeuxClient client = new BayeuxClient(url, transport);
client.getChannel(Channel.META_HANDSHAKE).addListener(new ClientSessionChannel.MessageListener() {
public void onMessage(ClientSessionChannel channel, Message message) {
System.out.println(message);
}
});
client.handshake();
获得
{"failure":{"exception":"org.cometd.common.TransportException: {httpCode=403}","message":{"supportedConnectionTypes":["long-polling"],"channel":"/meta/handshake","id":"2","version":"1.0"},"httpCode":403,"connectionType":"long-polling"},"channel":"/meta/handshake","id":"2","subscription":null,"successful":false}
所以我的第一个猜测是添加授权header。我怎样才能做到这一点? Jetty 9 用于服务器和客户端代码库。
请查看显示操作方法的 this test case。