获取不支持的AMF版本错误,而使用AMF连接来发送消息弯曲(Getting Unsupported

2019-10-24 12:56发布

我试图发送使用AMF连接API,但得到以下错误,如下图所示AMF消息。

ClientStatusException 
message: Unsupported AMF version

我使用BlazeDS的核心 - 4.0.1.21287.jar用于这一目的。

以下是我的代码。

String url = "https://10.222.73.251:9443/vsphere-client/#";
        try {
            amfConnection.connect(url);
            System.out.println(amfConnection.getUrl());
        } catch (ClientStatusException cse) {
            System.out.println("Error connecting url: " + cse);
            return;
        }

        try {

            amfConnection.addHttpRequestHeader("Cookie",
                    "6250CED9FBC7D5894B79973DEC1503A6");
            amfConnection.addHttpRequestHeader("Content-type",
                    "application/x-amf");
            amfConnection.setAmfTrace(new AmfTrace());
            //amfConnection.setObjectEncoding(3);
            System.out.println(amfConnection.getObjectEncoding());

            CommandMessage cmsg = new CommandMessage();
            cmsg.setOperation(CommandMessage.CLIENT_PING_OPERATION);
            cmsg.setMessageId(UUIDUtils.createUUID());
            cmsg.setHeader(Message.FLEX_CLIENT_ID_HEADER, "706E5399-D81A-11C8-11F7-BE5F1940632E");
            cmsg.setHeader(Message.ENDPOINT_HEADER, "amf");
            AcknowledgeMessage ack = (AcknowledgeMessage)amfConnection.call(null, cmsg);

任何帮助表示赞赏。 :)

Answer 1:

我有同样的问题。 其原因是,服务器预期“自足AMF包”。

见https://en.wikipedia.org/wiki/Action_Message_Format#AMF_self-contained_pa​​cket

这基本上意味着你需要添加下面的字节中的“正常”的AMF消息的前面:

  byte[] header = 
  { 0x00, 0x03,       // version 
    0x00, 0x00,       // nr of "header-type-structures" to follow (none) 
    0x00, 0x01,       // nr of "message-type-structures" to follow (one)
    0x00, 0x04,       // target-uri-length
    0x6e, 0x75, 0x6c, 0x6c, // target uri "null" 
    0x00, 0x04,       // response uri length 
    0x6e, 0x75, 0x6c, 0x6c, // response uri "null" 

    ??, ??, ??, ??    // the length of the "normal" message, 32 bits
  };


文章来源: Getting Unsupported AMF version error while using AMF Connection to send flex message