StackOverflow 的好心人,请帮忙。
我已经在我的 ubuntu 机器上设置了一个 ejabberd 服务器,添加了虚拟主机,设置
{访问,注册,[{允许,全部}]}。
并注册了一个管理员帐户。我不是 Linux 专家,但我已经成功完成了这个基本设置。
现在,在我的 Win 7 计算机上,使用 Pidgin,我可以以管理员身份登录并访问许多管理功能。最重要的是我可以在服务器上创建新用户。
问题是我无法使用 asmack 库对我的 Android 客户端执行此操作。我可以建立连接并登录,但是当我尝试通过帐户管理器或发送 IQ 数据包注册新用户时,我收到禁止(403)响应错误。
AccountManager am = new AccountManager(connection);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", "my_user_name");
attributes.put("password", "my_password");
attributes.put("email", "[email protected] /cdn-cgi/l/email-protection");
attributes.put("name", "my_full_name");
am.createAccount("my_user_name", "my_password", attributes);
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
// attributes.put("username", username);
// attributes.put("password", password);
// reg.setAttributes(attributes);
reg.addAttribute("username", username);
reg.addAttribute("password", password);
reg.addAttribute("email", email);
reg.addAttribute("name", fullName);
PacketFilter filter = new AndFilter(new PacketIDFilter(
reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
有没有人遇到过类似的问题或者可以告诉我我做错了什么?
Thanks
这是我的 LogCat
10-10 10:00:26.249: DEBUG/StatusBarPolicy(1639): [BRIGHTHY] curNetwork=22003 curHPLMN=22003
10-10 10:00:26.839: INFO/System.out(21277): 10:00:26 AM SENT (1080244736): <iq id="fMJxx-4" to="morena.local" type="get"><query xmlns="jabber:iq:register"></query></iq>
10-10 10:00:26.869: INFO/System.out(21277): 10:00:26 AM RCV (1080244736): <iq from='morena.local' to='[email protected] /cdn-cgi/l/email-protection/Smack' id='fMJxx-4' type='result'><query xmlns='jabber:iq:register'><instructions>Choose a username and password to register with this server</instructions><username>admin</username><password/><registered/></query></iq>
10-10 10:00:26.959: INFO/System.out(21277): 10:00:26 AM SENT (1080244736): <iq id="fMJxx-5" to="morena.local" type="set"><query xmlns="jabber:iq:register"><password>new_user</password><username>[email protected] /cdn-cgi/l/email-protection</username></query></iq>
10-10 10:00:26.969: INFO/System.out(21277): 10:00:26 AM RCV (1080244736): <iq from='morena.local' to='[email protected] /cdn-cgi/l/email-protection/Smack' id='fMJxx-5' type='error'><query xmlns='jabber:iq:register'><password>new_user</password><username>[email protected] /cdn-cgi/l/email-protection</username></query><error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
10-10 10:00:31.659: WARN/System.err(21277): forbidden(403)
10-10 10:00:31.659: WARN/System.err(21277): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:246)
10-10 10:00:31.659: WARN/System.err(21277): at org.jivesoftware.smack.AccountManager.createAccount(AccountManager.java:207)
10-10 10:00:31.659: WARN/System.err(21277): at org.me.my_project.FriendProfileActivity.connectToServer(FriendProfileActivity.java:698)
10-10 10:00:31.659: WARN/System.err(21277): at org.me.my_project.FriendProfileActivity.connectLogin(FriendProfileActivity.java:578)
10-10 10:00:31.659: WARN/System.err(21277): at org.me.my_project.FriendProfileActivity$2.run(FriendProfileActivity.java:433)
10-10 10:00:31.659: INFO/System.out(21277): 10:00:31 AM SENT (1080244736): <iq id="fMJxx-6" to="morena.local" type="get"><query xmlns="jabber:iq:register"></query></iq>
10-10 10:00:31.679: INFO/System.out(21277): 10:00:31 AM RCV (1080244736): <iq from='morena.local' to='[email protected] /cdn-cgi/l/email-protection/Smack' id='fMJxx-6' type='result'><query xmlns='jabber:iq:register'><instructions>Choose a username and password to register with this server</instructions><username>admin</username><password/><registered/></query></iq>
10-10 10:00:31.689: INFO/System.out(21277): 10:00:31 AM SENT (1080244736): <iq id="fMJxx-7" to="morena.local" type="set"><query xmlns="jabber:iq:register"><email>[email protected] /cdn-cgi/l/email-protection</email><password>new_user1</password><username>[email protected] /cdn-cgi/l/email-protection</username><name>[email protected] /cdn-cgi/l/email-protection</name></query></iq>
10-10 10:00:31.699: INFO/System.out(21277): 10:00:31 AM RCV (1080244736): <iq from='morena.local' to='[email protected] /cdn-cgi/l/email-protection/Smack' id='fMJxx-7' type='error'><query xmlns='jabber:iq:register'><email>[email protected] /cdn-cgi/l/email-protection</email><password>new_user1</password><username>[email protected] /cdn-cgi/l/email-protection</username><name>[email protected] /cdn-cgi/l/email-protection</name></query><error code='403' type='auth'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
10-10 10:00:31.729: WARN/System.err(21277): forbidden(403)
10-10 10:00:31.729: WARN/System.err(21277): at org.me.my_project.utilities.CreateChatAccount.createAccount(CreateChatAccount.java:100)
10-10 10:00:31.729: WARN/System.err(21277): at org.me.my_project.utilities.CreateChatAccount.createAccount(CreateChatAccount.java:143)
10-10 10:00:31.729: WARN/System.err(21277): at org.me.my_project.FriendProfileActivity.connectToServer(FriendProfileActivity.java:706)
10-10 10:00:31.729: WARN/System.err(21277): at org.me.my_project.FriendProfileActivity.connectLogin(FriendProfileActivity.java:578)
10-10 10:00:31.729: WARN/System.err(21277): at org.me.my_project.FriendProfileActivity$2.run(FriendProfileActivity.java:433)