通过 Smack 添加新用户到 ejabberd android api
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
。
我已经在 ejabberd 服务器中将我的 register
规则更改为 allow all
。我不认为它有任何问题,因为我可以从 spark 创建帐户,但在 smack 中出现错误。
我已经研究了以下与此主题相关的 SO 问题,但没有成功。
- Ejabberd can't register new user
- How to register a new user on XMPP using (a)Smack library
有人对如何解决这个问题有什么建议吗?
请尝试以下 -
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}]}.
这意味着 - 带内注册允许注册任何可能的用户名。要禁用带内注册,请将 'allow' 替换为 'deny'。
并且在 mod_register 中(同一配置文件中的模块)请在下面设置 -
{access_from, register}
& 在此之前请检查您是否已连接到 XMPP 服务器。
这可能会解决您的问题。
我已经在本地服务器上安装了 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
。
我已经在 ejabberd 服务器中将我的 register
规则更改为 allow all
。我不认为它有任何问题,因为我可以从 spark 创建帐户,但在 smack 中出现错误。
我已经研究了以下与此主题相关的 SO 问题,但没有成功。
- Ejabberd can't register new user
- How to register a new user on XMPP using (a)Smack library
有人对如何解决这个问题有什么建议吗?
请尝试以下 -
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}]}.
这意味着 - 带内注册允许注册任何可能的用户名。要禁用带内注册,请将 'allow' 替换为 'deny'。
并且在 mod_register 中(同一配置文件中的模块)请在下面设置 -
{access_from, register}
& 在此之前请检查您是否已连接到 XMPP 服务器。
这可能会解决您的问题。