嗨,我正在研究 ejabberd,我对这项技术很陌生。
我正在尝试使用以下代码在我的 ejabberd 服务器上添加一个用户:
try {
conf.setSASLAuthenticationEnabled(true);
connection.connect();
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
Log.i("XMPPClient", "Connected to "
+connection.getHost());
createUser("tester","testerpass");
}
} catch (XMPPException e1) {
Log.e("XMPPClient", e1.toString());
xmppClient.setConnection(null);
}
public void createUser(String user, String pass) {
try {
//Admin login
connection.login(user, pass);
} catch (XMPPException e) {
e.printStackTrace();
}
Log.i("connection.isAuthenticated() : ",""+connection.isAuthenticated() );
if (connection.isAuthenticated()) {
AccountManager manager = connection.getAccountManager();
try {
manager.createAccount(user, pass);
} catch (XMPPException e) {
Log.w("[create_user] Cannot create new user: XMPP Exception.", "0");
e.printStackTrace();
} catch (IllegalStateException e) {
Log.w("[create_user] Cannot create new user: not logged in.", "0");
e.printStackTrace();
}
}
}
它连接到服务器和管理员登录是完美的但是在创建新帐户期间它给出了禁止的 403 错误,即:
06-15 20:01:40.092: I/XMPPClient(1300):Connected to 68.178.255.136
06-15 20:01:41.952: I/connection.isAuthenticated() :(1300): true
06-15 20:01:42.562: W/[create_user] Cannot create new user: XMPP Exception.(1300): 0
06-15 20:01:42.562: W/System.err(1300): forbidden(403)
06-15 20:01:42.562: W/System.err(1300): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246)
如果有人可以为此建议一个解决方法,我将非常感激。