![](/img/trans.png)
[英]IN XMPP getting exception not-authorized(401), while submitting the form
[英]Not able to join Chatroom smack/smackx, XMPP: Exception not-authorized (401)
我是使用 smack/smackx 庫處理 MultiUserChat (groupchat) 的新手,在加入現有公共聊天室時遇到困難並遇到錯誤 (Exceptionnot-authorized(401) )。 用戶通過聊天室的客戶端登錄,我可以在 openfire 中看到它。 根據我對發起群聊的理解,用戶需要再次創建/加入。 下面是我到目前為止編寫的代碼(為簡潔起見,我保持簡短)。 一切似乎都很好,用戶可以登錄服務器,但是一旦程序嘗試加入房間,我就會收到未授權 (401) 錯誤。 我曾嘗試使用昵稱加入,也嘗試使用帶密碼的昵稱加入,但結果相同。
為此,我正在瀏覽 web 上可用的材料,並嘗試了可用的解決方案,但沒有成功。 我確定我犯了一些基本錯誤。 在這個方向上的任何指針將不勝感激。
@SuppressWarnings("deprecation")
public boolean isGroupChatAlreadyCreated(@NonNull final EntityBareJid groupId)
throws XmppStringprepException,
NotAMucServiceException,
NotConnectedException,
InterruptedException,
NoResponseException, XMPPException
{
muc = new MultiUserChat(connection, "xyz@conference.abc");
muc.create("xyz");
Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for(Iterator fields = form.getFields();fields.hasNext();) {
FormField field = (FormField)fields.next();
if(!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable()!= null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("#muc#roomconfig_publicroom", true);
muc.sendConfigurationForm(submitForm);
System.out.println("Reaching before join");
//Getting error NOT-AuTHORIZED (401) here
muc.join("xyz");
}
首先,您需要創建一個連接。 連接到服務器並進行身份驗證。 只有這樣你才能創建 MUC。
從您的代碼中我得到您沒有進行身份驗證的印象,因此嘗試匿名加入或創建聊天。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.