创建用户,变得不可接受(406)
我正在使用 asmack XMPP 和 android 代码。我登录 XMPP 服务器一切正常,但当我尝试创建新用户时出现问题。我想要实现的是:
- 以管理员身份登录。
- 创建一个新用户。
- 从管理员处注销。
- 以新创建的用户身份登录。
- 做一些动作——玩游戏。
- 删除新创建的用户。
这允许玩家不注册,因为注册是自动处理的,并且还允许用户选择当前仍然可用的任何名称。
目前的代码如下:
public void create_user(String username, String password) {
try {
connection.login("user", "pass");
} catch (XMPPException e) {
e.printStackTrace();
}
if (connection.isAuthenticated()) {
AccountManager manager = connection.getAccountManager();
try {
manager.createAccount(username, password);
} 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();
}
}
}
代码的登录部分是成功的。代码的第二部分不是。我收到以下错误:
W/[create_user] Cannot create new user: XMPP Exception.( 1525): 0
W/System.err( 1525): not-acceptable(406)
W/System.err( 1525): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246)
W/System.err( 1525): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:207)
W/System.err( 1525): at company.games.boxer.XMPPManager.create_user(XMPPManager.java:81)
W/System.err( 1525): at company.games.boxer.XMPPManager.xmpp_login(XMPPManager.java:113)
W/System.err( 1525): at company.games.boxer.XMPPClient.onCreate(XMPPClient.java:19)
W/System.err( 1525): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err( 1525): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/System.err( 1525): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/System.err( 1525): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/System.err( 1525): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/System.err( 1525): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1525): at android.os.Looper.loop(Looper.java:123)
W/System.err( 1525): at android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err( 1525): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1525): at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err( 1525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/System.err( 1525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/System.err( 1525): at dalvik.system.NativeStart.main(Native Method)
有人可以告诉我为什么吗?我有足够的权限来创建用户,因为我以 user:pass (这是 XMPP 服务器的管理员)身份登录。
I'm using asmack XMPP with android code. I'm logging-in the XMPP server just fine, but the problem occurs when I'm trying to create a new user. What I want to achieve is the following:
- Login with administrator.
- Create a new user.
- Logout from administrator.
- Login as a newly craeted user.
- Do some actions - play the game.
- Delete the newly created user.
This allows the players to not register, since the registration is handled automatically and also allows users to choose whatever name is still available at a current time.
The current code is the following:
public void create_user(String username, String password) {
try {
connection.login("user", "pass");
} catch (XMPPException e) {
e.printStackTrace();
}
if (connection.isAuthenticated()) {
AccountManager manager = connection.getAccountManager();
try {
manager.createAccount(username, password);
} 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();
}
}
}
The login part of the code is sucessful. The second part of the code is not. I'm receiving the following error:
W/[create_user] Cannot create new user: XMPP Exception.( 1525): 0
W/System.err( 1525): not-acceptable(406)
W/System.err( 1525): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246)
W/System.err( 1525): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:207)
W/System.err( 1525): at company.games.boxer.XMPPManager.create_user(XMPPManager.java:81)
W/System.err( 1525): at company.games.boxer.XMPPManager.xmpp_login(XMPPManager.java:113)
W/System.err( 1525): at company.games.boxer.XMPPClient.onCreate(XMPPClient.java:19)
W/System.err( 1525): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err( 1525): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/System.err( 1525): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/System.err( 1525): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/System.err( 1525): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/System.err( 1525): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1525): at android.os.Looper.loop(Looper.java:123)
W/System.err( 1525): at android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err( 1525): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1525): at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err( 1525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/System.err( 1525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/System.err( 1525): at dalvik.system.NativeStart.main(Native Method)
Can somebody tell me why? I have sufficient permissions to create users, since I'm logging in as user:pass (which is an administrator of the XMPP server).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 smack docs,它在这里说
这与 XEP-0077 中的注册错误一致('示例 7 . 主机通知实体注册失败(未提供一些必需的信息)。
您应该使用
getAccountAttributes()
,以及启用 smack 调试器来查看发送/接收的数据,以确保您拥有所有数据所需的标签。我希望这有助于解决这个问题。
Take a look in the smack docs, it here says that
This is consistent with the registration error in XEP-0077 ('example 7. Host Informs Entity of Failed Registration (Some Required Information Not Provided)').
You should check the required attributes with
getAccountAttributes()
, as well as enable the smack debugger to see what data is sent/received to make sure you have all the needed tags.I hope this helps with the problem.