首先,这可能是一个重复的问题,但出于好奇,我问了。
我正在使用 openfire 使用 swift 语言开发 XMPP 项目。经过一番搜索,我成功注册了一个用户。现在,当我想向用户发送消息时,它会抛出错误 404,未找到远程服务器。我不知道为什么会发生这种情况。
这是我发送消息的代码:
let sendToUser = strUserName + "@" + kAppDelegate.strJDomain
let body = XMLElement.element(withName: "body") as! XMLElement
body.stringValue = tv_Message.text!
let thread = XMLElement.element(withName: "thread", stringValue: "messageThread") as! XMLElement
let messageBody = XMLElement.element(withName: "message") as! XMLElement
messageBody.addAttribute(withName: "type", stringValue: "chat")
messageBody.addAttribute(withName: "to", stringValue: sendToUser)
messageBody.addChild(body)
messageBody.addChild(thread)
messageBody.addAttribute(withName: "id", stringValue: (kAppDelegate.xmppStream?.generateUUID())!)
kAppDelegate.xmppStream?.send(messageBody)
当我点击“发送”时,它会抛出一个错误:
SEND: <message type="chat" to="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d9d3d0d1d4ddcbd0f8898180968b80968080968a8d8c" rel="noreferrer noopener nofollow">[email protected]</a>"><body>Hello</body><thread id="3087B0E8-F926-426B-9B8F-15473F4404F2">messageThread</thread></message>
RECV: <message xmlns="jabber:client" to="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6601091314071026101615481607140d0e1f0748091401" rel="noreferrer noopener nofollow">[email protected]</a>/411dv3ejcj" from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3352585b5a5f56405b73020a0b1d000b1d0b0b1d010607" rel="noreferrer noopener nofollow">[email protected]</a>" type="error"><thread>messageThread</thread><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></message>
我使用的端口号:5222
当我登录开火时,它正确地向我显示用户在线状态,而当我尝试发送消息时,它不起作用。我使用了一些引用资料但没有得到结果。除此之外,我还设置了开火设置并激活了所有必需的插件。
最佳答案
首先,您要为发送者和接收者发送两个不同的域名。您需要检查哪一个是正确的并进行设置。
正确的信息将显示在 openfire 默认主页上,即服务器信息中。您可以从那里进行更正。毕竟,您不会收到这些错误。
关于iOS 发送消息时出现错误 404 远程服务器未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46154733/