0
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}
所以我的第一個猜測是添加授權頭。我怎樣才能做到這一點? Jetty 9用於服務器和客戶端代碼庫。