在android中使用asmack获取错误请求400错误

时间:2014-02-06 08:11:09

标签: android xmpp ejabberd asmack

我正在尝试使用我的XMPP客户端在ejabberd服务器上使用Android中的asmack库注册新用户。问题是我得到了以下错误&用户未在服务器上创建:

bad-request(400)
at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:243)
at in.ui.MainActivity$1$1$1.run(MainActivity.java:316)
at java.lang.Thread.run(Thread.java:841)

以下是代码:

_xmppUsername = XMPPConfig.getStringUserInfoValue (XMPPConfig.XMPP_CLIENT_ID);
_xmppPassword = XMPPConfig.getStringUserInfoValue (XMPPConfig.XMPP_CLIENT_PASSWORD);
_xmppHost = XMPPConfig.getStringUserInfoValue (XMPPConfig.XMPP_HOST);
try {
    _xmppPortNo = Integer.parseInt (XMPPConfig.getStringUserInfoValue (XMPPConfig.XMPP_PORT));
} catch (Exception e) {
    e.printStackTrace ();
    Log.e (TAG, e.getMessage ());
}
_xmppServiceName = XMPPConfig.getStringUserInfoValue (XMPPConfig.XMPP_SERVICE_NAME);

ConnectionConfiguration conConfig = new ConnectionConfiguration (_xmppHost, _xmppPortNo, _xmppServiceName);

_xmppConnection = new XMPPConnection (conConfig);

if (!_xmppConnection.isAuthenticated ()) {
    login ();
}
/*
 * If connection has not been established or had been established &
 * broken again then login
 */

    @Override
    public void onShow (final DialogInterface dialog) {
        Button positiveButton = _dlgRegistration.getButton (DialogInterface.BUTTON_POSITIVE);
        positiveButton.setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick (View v) {

                // Creating registration thread
                new Thread (new Runnable () {
                    @Override
                    public void run () {
                        String clientID = null;
                        String password = null;

                            clientID = "user" + XMPP_SERVICE_NAME;
                            try {

                                // Getting hash password from UUID
                                password = "password";
                                Log.i (TAG, clientID + password);
                            } catch (NoSuchAlgorithmException e1) {
                                e1.printStackTrace ();
                            } catch (UnsupportedEncodingException e1) {
                                e1.printStackTrace ();
                            }
                        }
                        AccountManager manager = _xmppConnection.getAccountManager ();
                        try {


                                // Creating account on the server
                                manager.createAccount (clientID, password, attr);

                                                            }
                        } catch (XMPPException e) {
                            e.printStackTrace ();
                        }
                    }
                }).start ();
            }
        });

1 个答案:

答案 0 :(得分:3)

问题在于这一行clientID = "user" + XMPP_SERVICE_NAME;我不应该在"user"之后附加域名或服务名称。