【问题标题】:Getting bad request 400 error using asmack in android在android中使用asmack获取错误的请求400错误
【发布时间】:2014-02-06 08:11:09
【问题描述】:

我正在尝试使用我的 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 ();
            }
        });

【问题讨论】:

    标签: android xmpp ejabberd asmack


    【解决方案1】:

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

    【讨论】:

    • 嘿抱歉问。您提到 { clientID = "user" + XMPP_SERVICE_NAME } 不需要服务名称。但是,就我而言,我的用户名本身包含您上面提到的结构。我希望我的实际客户就像这个 clientID = "abc@xyz.com" + XMPP_SERVICE_NAME 如果在这里我没有提到服务名称,那么我的客户我会像这个 clientID = "abc@xyz. com”,这意味着我的用户是“abc”,我的服务是“xyz.com”。你能帮我解决这个问题吗?我怎样才能使用以下格式创建用户 user = abc@xyz.com 谢谢。 :)
    猜你喜欢
    • 2017-11-27
    • 2013-06-30
    • 2017-11-30
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多