gpt4 book ai didi

Android、Openfire、Smack、XMPP

转载 作者:行者123 更新时间:2023-11-30 01:16:11 25 4
gpt4 key购买 nike

我想在 android 中使用 smack 匿名注册新用户到 openfire。我正在使用 Smack 4.1.0 和 Openfire 4.0.2。如果我使用已经注册的用户登录,然后尝试注册,那么它就可以完美运行。但我想注册而不用其他帐户登录。

我也提到了Smack 4.1 Android anonymous registration to Openfire但它也不起作用。

连接生成器:

    Configure conf = new Configure();
conf.configure(new ProviderManager());

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setServiceName(serverAddress);
config.setHost(serverAddress);
config.setPort(5222);
config.setResource(context.getResources().getString(R.string.resource_name));
config.setDebuggerEnabled(true);
config.setSendPresence(true);
XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
mConnection = new XMPPTCPConnection(config.build());
XMPPConnectionListener connectionListener = new XMPPConnectionListener(type);
mConnection.addConnectionListener(connectionListener);

用户注册:

public void createNewAccount() {
AccountManager accountManager =AccountManager.getInstance(mConnection);
if (accountManager != null) {
Log.d("Account manager", "NOT NULL");
accountManager.sensitiveOperationOverInsecureConnection(true);
Map<String, String> attr = new HashMap<String, String>();
attr.put("username", loginUser);
attr.put("password", passwordUser);
attr.put("email", loginUser);
try {
accountManager.createAccount(loginUser, passwordUser, attr);
accountCreated = true;
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
}
} else {
Log.d("Account manager", "NULL");
}
}

我得到了错误的请求错误。

 06-15 15:53:27.332 2026-10349/com.dsquare.dchat I/System.out: 03:53:27 PM SENT (0): <iq to='192.168.0.250' id='IAX28-1' type='set'><query xmlns='jabber:iq:register'><email>dharmesh1</email><password>dharmesh1</passwor d><username>dharmesh1</username></query></iq>
06-15 15:53:27.364 2026-10350/com.dsquare.dchat I/System.out: 03:53:27 PM RECV (0): <iq type="error" id="IAX28-1" from="192.168.0.250" to="divyang-pc/9f351hyo93"><query xmlns="jabber:iq:register"><email>dharmesh1</email><password>dharmesh1</passwor d><username>dharmesh1</username></query><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
06-15 15:53:27.440 2026-10348/com.dsquare.dchat W/System.err: org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: bad-request - modify
06-15 15:53:27.468 2026-10348/com.dsquare.dchat W/System.err: at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:2 32)
06-15 15:53:27.496 2026-10348/com.dsquare.dchat W/System.err: at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:2 13)
06-15 15:53:27.508 2026-10348/com.dsquare.dchat W/System.err: at org.jivesoftware.smackx.iqregister.AccountManager.createAccount(AccountManager. java:272)
06-15 15:53:27.512 2026-10348/com.dsquare.dchat W/System.err: at com.dsquare.xmppservices.XMPPConnection$XMPPConnectionListener.connected(XMPPCo nnection.java:989)
06-15 15:53:27.528 2026-10348/com.dsquare.dchat W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionConnectedListener(A bstractXMPPConnection.java:1152)
06-15 15:53:27.532 2026-10348/com.dsquare.dchat W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:841)
06-15 15:53:27.544 2026-10348/com.dsquare.dchat W/System.err: at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.ja va:360)
06-15 15:53:27.548 2026-10348/com.dsquare.dchat W/System.err: at com.dsquare.xmppservices.XMPPConnection$2.doInBackground(XMPPConnection.java:25 2)
06-15 15:53:27.552 2026-10348/com.dsquare.dchat W/System.err: at com.dsquare.xmppservices.XMPPConnection$2.doInBackground(XMPPConnection.java:23 4)
06-15 15:53:27.560 2026-10348/com.dsquare.dchat W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-15 15:53:27.564 2026-10348/com.dsquare.dchat W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-15 15:53:27.568 2026-10348/com.dsquare.dchat W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-15 15:53:27.576 2026-10348/com.dsquare.dchat W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-15 15:53:27.580 2026-10348/com.dsquare.dchat W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-15 15:53:27.584 2026-10348/com.dsquare.dchat W/System.err: at java.lang.Thread.run(Thread.java:841)

最佳答案

首先,您必须检查服务器设置/注册和登录是否具有注册帐户的正确权限。

您还可以:

accountManager.supportsAccountCreation()

检查此选项是否可用。

请检查您发送的属性。我认为您不需要输入密码并再次登录。

关于Android、Openfire、Smack、XMPP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37835273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com