[英]Adding new user to ejabberd through Smack android api
我已经在我的本地服务器上安装了ejabberd 。 然后在 spark 中对其功能进行了测试,并且运行良好。 现在我想通过 android 应用添加一个新用户。
我尝试通过 spark 添加一个新用户,效果很好。 我给出的字段是uesrname
、 password
、 confirm password
、 server
。 但是,当我尝试在 android 应用程序中使用smack api执行此操作时,出现以下错误:
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: forbidden - auth
我正在使用createAccount() ,在下面使用的代码中看到,在 smack 中创建新帐户。
AccountManager accountManager = AccountManager.getInstance(conn1);
try {
accountManager.createAccount("tryuser", "qwerty");
Log.i("log", "created user successfully");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
我已经检查过它是否支持通过supportsAccountCreation()创建新帐户并返回true
。
我已更改我的register
规则以allow all
在 ejabberd 服务器中。 我不认为它有任何问题,因为我可以从 spark 创建帐户,但在 smack 中出错。
我已经研究了与此主题相关的以下 SO 问题,但没有运气。
有没有人对如何解决这个问题有任何建议?
请尝试以下 -
AccountManager accountManager = AccountManager.getInstance(connection);
try {
if (accountManager.supportsAccountCreation()) {
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount("userName", "password");
}
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
并且您还需要在 ejabberd.cfg(配置文件)中进行以下设置
{access, register, [{allow, all}]}.
这意味着 - 带内注册允许注册任何可能的用户名。 要禁用带内注册,请将“允许”替换为“拒绝”。
在 mod_register (同一配置文件中的模块)中,请在下面设置 -
{access_from, register}
& 在此之前,请检查您是否已连接到 XMPP 服务器。
可能这将解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.