我从我的服务器可能的字段:
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser@company.com/iPhone" id="search1" type="result"><query xmlns="jabber:iq:search">
<instructions>You need an x:data capable client to search</instructions>
<x xmlns="jabber:x:data" type="form">
<title>Search users in vjud.company.com</title>
<instructions>Fill in the form to search for any matching Jabber User (Add * to the end of field to match substring)
</instructions>
<field type="text-single" label="User" var="user"/>
<field type="text-single" label="Full Name" var="fn"/>
<field type="text-single" label="Name" var="first"/>
<field type="text-single" label="Middle Name" var="middle"/>
<field type="text-single" label="Family Name" var="last"/>
<field type="text-single" label="Nickname" var="nick"/>
<field type="text-single" label="Birthday" var="bday"/>
<field type="text-single" label="Country" var="ctry"/>
<field type="text-single" label="City" var="locality"/>
<field type="text-single" label="Email" var="email"/>
<field type="text-single" label="Organization Name" var="orgname"/>
<field type="text-single" label="Organization Unit" var="orgunit"/>
</x>
</query>
</iq>
假设我想搜索与JID用户admin@company.com
由西港岛线的要求是这样的:
XMPPIQ *iq2 = [[XMPPIQ alloc] init];
[iq2 addAttributeWithName:@"type" stringValue:@"set"];
[iq2 addAttributeWithName:@"from" stringValue:@"testuser@company.com"];
[iq2 addAttributeWithName:@"to" stringValue:@"vjud.company.com"];
[iq2 addAttributeWithName:@"id" stringValue:@"search1"];
XMPPElement *query2 = [XMPPElement elementWithName:@"query"];
[query2 setXmlns:@"jabber:iq:search"];
XMPPElement *user = [XMPPElement elementWithName:@"user"];
[user setStringValue:@"admin"];
[iq2 addChild:query2];
[query addChild:user];
该错误节:
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser@company.com/iPhone" type="error" id="search1">
<query xmlns="jabber:iq:search"/>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
所以,基本上有2个问题:
- 为什么没有
</query>
响应元件? - 它是错误的实际原因是什么?
-The服务器的响应应该像这-
非常感谢@legoscia用户,如果请求是由正确的,你会得到这样的事情(通知<item>
元素):
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser@company.com/iPhone" id="search1" type="result»>
<query xmlns="jabber:iq:search"><x xmlns="jabber:x:data" type="result»>
<title>Search Results for vjud.company.com</title>
<reported>
<field type="text-single" label="Jabber ID" var="jid»/>
<field type="text-single" label="Full Name" var="fn»/>
<field type="text-single" label="Name" var="first»/>
<field type="text-single" label="Middle Name" var="middle»/>
<field type="text-single" label="Family Name" var="last"/><field type="text-single" label="Nickname" var="nick»/>
<field type="text-single" label="Birthday" var="bday»/>
<field type="text-single" label="Country" var="ctry»/>
<field type="text-single" label="City" var="locality»/>
<field type="text-single" label="Email" var="email»/>
<field type="text-single" label="Organization Name" var="orgname"/><field type="text-single" label="Organization Unit" var="orgunit»/>
</reported>
<item>
<field var="jid»>
<value>admin@company.com</value>
</field>
<field var="fn"><value/></field>
<field var="last"><value/></field>
<field var="first"><value/></field>
<field var="middle"><value/></field>
<field var="nick"><value/></field>
<field var="bday"><value/></field>
<field var="ctry"><value/></field>
<field var="locality"><value/></field>
<field var="email"><value/></field>
<field var="orgname"><value/></field>
<field var="orgunit"><value/></field></item>
</x>
</query>
</iq>
如果没有比赛,你只会收到<reported>
元素有很多领域。 您可能希望有看看这个为好。