【问题标题】:How to add request header to BayeuxClient如何将请求标头添加到 BayeuxClient
【发布时间】:2016-04-13 13:01:32
【问题描述】:
  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 用于服务器和客户端代码库。

【问题讨论】:

    标签: cometd request-headers bayeux


    【解决方案1】:

    请查看this test case,它显示了如何操作。

    【讨论】:

    猜你喜欢
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2012-12-01
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多