如何发送iq到搜索"用户名"指示由iOS上的Openfire实施的XEP-0055

时间:2016-05-13 07:36:54

标签: ios xmpp

我正在使用XMPP处理即时消息应用。我想在添加朋友时搜索用户以确定用户是否存在。我在http://xmpp.org/extensions/xep-0055.html上阅读了XEP-0055,并发送了iq,如示例1.请求搜索字段。然后我收到了以下回复:

<iq xmlns="jabber:client" type="result" id="search2" from="search.127.0.0.1" to="admin@127.0.0.1/iPhone">
    <query xmlns="jabber:iq:search">
        <instructions>
            The following fields are available for searching. Wildcard (*) characters are allowed as part of the query.
        </instructions>
        <first></first>
        <last></last>
        <nick></nick>
        <email></email>
        <x xmlns="jabber:x:data" type="form">
            <title>
                Advanced User Search
            </title>
            <instructions>
                The following fields are available for searching. Wildcard (*) characters are allowed as part of the query.
            </instructions>
            <field var="FORM_TYPE" type="hidden">
                <value>jabber:iq:search</value>
            </field>
            <field var="search" type="text-single" label="Search">
                <required></required>
            </field>
            <field var="Username" type="boolean" label="Username">
                <value>1</value>
            </field>
            <field var="Name" type="boolean" label="Name">
                <value>1</value>
            </field>
            <field var="Email" type="boolean" label="Email">
                <value>1</value>
            </field>
        </x>
    </query>
</iq>

我想搜索字段&#34;用户名&#34;我发送了iq

<iq type="set" to="search.127.0.0.1" id="search2" from="admin@127.0.0.1" xml:lang="en"><query xmlns="jabber:iq:search"><Username>gq</Username></query></iq>

但我收到了错误回复

<iq xmlns="jabber:client" type="error" id="search2" from="search.127.0.0.1" to="admin@127.0.0.1/iPhone"><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></bad-request></error></iq>

我知道iq的格式一定是错的。但我真的不知道它应该是什么格式。任何人都可以搞清楚吗?

1 个答案:

答案 0 :(得分:0)

我在iOS XMPP searching users by username上找到答案 它非常有用,我可以在添加朋友时应用它。