如何使用Java的Smack API发送自定义XML数据包? [英] How to send custom XML packet using Java's Smack API?

查看:125
本文介绍了如何使用Java的Smack API发送自定义XML数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java中的Smack API连接到我的XMPP服务器。



我想发送一个这样的自定义消息包:

  < message to =you@MyServer.comtype =chatMYFIELD =custom stuff> 
< body>嗨< / body>
< CUSTOM_STANZA A =...B =...>
C =...
D =...
< / CUSTOM_STANZA>
< / message>

我猜我创建了我自己的数据包,它返回了这个XML的toXML()方法。但这似乎不起作用。



任何帮助将不胜感激。

解决方案

您需要定义实现ExtensionElement 自定义类 (由@ 流量表示)



一个非常详细的解释可以使用在此答案中提供以下节目。

 < message id ='923442621149'type ='chat'>< body> shanraisshan< / body> 
< reply xmlns ='shayan:reply'rText ='这是自定义属性'/>
< / message>

其中回复是自定义扩展程序,其中包含


  1. 元素(回复)

  2. 命名空间(shayan: ()官方XMPP网站


    I'm using the Smack API in Java to connect to my XMPP server.

    I want to send a customized message packet like this:

    <message to="you@MyServer.com" type="chat" MYFIELD="custom stuff">
        <body> hi </body>
        <CUSTOM_STANZA A="..." B="..."> 
            C="..." 
            D="..."
        </CUSTOM_STANZA>
    </message>
    

    I'm guessing that I create implement my own Packet with that returns this XML in it's toXML() method. But that doesn't seem to work.

    Any help would be appreciated.

    解决方案

    You need to define a custom class that should implements ExtensionElement (as menitioned by @Flow)

    A very detailed explanation that produces the following stanza is available in this answer

    <message id='923442621149' type='chat'><body>shanraisshan</body>
    <reply xmlns='shayan:reply' rText='this is custom attribute'/>
    </message>
    

    where reply is a custom extension, which contains

    1. Element (reply)
    2. Namespace (shayan:reply)

    the list of default xmpp namespaces are available at Official XMPP website

    这篇关于如何使用Java的Smack API发送自定义XML数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆