注册新用户Openfire服务器返回bad-request节

时间:2015-05-05 14:48:34

标签: android xmpp openfire smack asmack

我正在尝试使用以下代码使用aSmack 4注册新用户:

ConnectionConfiguration config = new ConnectionConfiguration(Constant.XMPP_HOST, Constant.XMPP_PORT);
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
conn2 = new XMPPTCPConnection(config);

String user ="bear";
String pass = "123";
String email = "bear@bear.com";
HashMap<String,String> attr = new HashMap<String, String>();
attr.put("username",user);
attr.put("password",pass);
attr.put("email", email);
if(conn2!=null) {

Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(conn2.getServiceName());
reg.setAttributes(attr);
PacketFilter filter = new AndFilter(new PacketIDFilter(
        reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = conn2 .createPacketCollector(filter);
try {
    conn2.sendPacket(reg);
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
}
IQ result = (IQ) collector.nextResult(SmackConfiguration
        .getDefaultPacketReplyTimeout());
System.out.println(result);
collector.cancel(); 

但Openfire服务器返回此数据包,我不知道它是什么意思。

<iq id='XILKN-9' to='pc-pc/b529612d' from='192.168.21.107' type='error'>
      <query xmlns='jabber:iq:register'>
          <password>123</password>
          <email>bear@bear.com</email>
          <username>bear</username>
     </query>
     <error type="modify">
          <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
    </error>
</iq>

问题是什么?我正在使用OpenFire 3.9.3和aSmack 4.0.7。

1 个答案:

答案 0 :(得分:0)

我知道现在为时已晚,但希望能帮助别人。 在您的连接配置中,请确保setServiceName正确。 I.e config.setServiceName(Name of your service);