获取使用android系统中asmack错误请求400错误 [英] Getting bad request 400 error using asmack in android

查看:719
本文介绍了获取使用android系统中asmack错误请求400错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用登记我的XMPP客户端使用asmack库中的Andr​​oid ejabberd服务器上的新用户。问题是,我收到以下错误:放大器;是不是在服务器上创建的用户:

 坏请求(400)
在org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:243)
在in.ui.MainActivity $ 1 $ 1 $ 1.run(MainActivity.java:316)
在java.lang.Thread.run(Thread.java:841)

以下是code:

  _xmppUsername = XMPPConfig.getStringUserInfoValue(XMPPConfig.XMPP_CLIENT_ID);
_xmppPassword = XMPPConfig.getStringUserInfoValue(XMPPConfig.XMPP_CLIENT_PASSWORD);
_xmppHost = XMPPConfig.getStringUserInfoValue(XMPPConfig.XMPP_HOST);
尝试{
    _xmppPortNo =的Integer.parseInt(XMPPConfig.getStringUserInfoValue(XMPPConfig.XMPP_PORT));
}赶上(例外五){
    e.printStackTrace();
    Log.e(TAG,e.getMessage());
}
_xmppServiceName = XMPPConfig.getStringUserInfoValue(XMPPConfig.XMPP_SERVICE_NAME);ConnectionConfiguration conconfig的=新ConnectionConfiguration(_xmppHost,_xmppPortNo,_xmppServiceName);_xmppConnection =新XMPPConnection(安装了conconfig);如果(!_xmppConnection.isAuthenticated()){
    登录 ();
}
/ *
 *如果连接没有建立或已建立与放大器;
 *再破请登录
 * /    @覆盖
    公共无效昂秀(最终DialogInterface对话){
        按钮positiveButton = _dlgRegistration.getButton(DialogInterface.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(新View.OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){                //创建线程注册
                新主题(新的Runnable接口(){
                    @覆盖
                    公共无效的run(){
                        字符串clientID的= NULL;
                        字符串密码= NULL;                            clientID的=用户+ XMPP_SERVICE_NAME;
                            尝试{                                //充分利用UUID的哈希密码
                                密码=密码;
                                Log.i(TAG,clientID的+密码);
                            }赶上(抛出:NoSuchAlgorithmException E1){
                                e1.printStackTrace();
                            }赶上(UnsupportedEncodingException E1){
                                e1.printStackTrace();
                            }
                        }
                        的AccountManager经理= _xmppConnection.getAccountManager();
                        尝试{
                                //在服务器上创建账户
                                manager.createAccount(客户端ID,密码,attr)使用;                                                            }
                        }赶上(XMPPException E){
                            e.printStackTrace();
                        }
                    }
                })开始();
            }
        });


解决方案

但问题是这一行 clientID的=用户+ XMPP_SERVICE_NAME; 其中,我不应该被之后追加域或服务名称用户

I am trying to register a new user using my XMPP client using asmack library in Android on ejabberd server. The problem is that I am getting following error & the user is not being created on the server:

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)

Following is the code:

_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 ();
            }
        });

解决方案

The problem was this line clientID = "user" + XMPP_SERVICE_NAME; where I shouldn't have been appending Domain or Service Name after "user".

这篇关于获取使用android系统中asmack错误请求400错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆