首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过Ionic应用程序进行Openfire XMPP客户端连接

通过Ionic应用程序进行Openfire XMPP客户端连接
EN

Stack Overflow用户
提问于 2020-10-01 13:39:00
回答 1查看 225关注 0票数 1

为了测试与Openfire XMPP服务器的客户端连接,首先测试了以下测试脚本(nodejs),该脚本成功运行。

代码语言:javascript
运行
复制
async function connectX() {
    try {
        const keyPair = await XmppUser.generateKeys()
        XmppUser.connect(username, password, keyPairs).then(
           async user => {
                        user.getFriends().then(friends => {
                            console.log("List of Friends: ");
                            console.log(friends);
                            user.getChatHistory().then(history => {
                                console.log("Chat History: ")
                                console.log(history);
                                user.closeConnection();
                            }).catch(e => console.log(e));
                        }).catch(e => console.log(e));
            }
        ).catch(e => console.log(e));
    } catch(e) {
        console.log(e)
    }
}

connectX()

输出:

代码语言:javascript
运行
复制
List of Friends:
[ 'test1.test@chat.company.io', 'test2.test@chat.company.io' ]

Chat History:
{ messages:
   [ { date: 2020-08-11T12:18:34.314Z,
       from: 'test1.test@chat.company.io',
       to: 'test6.test@chat.company.io',
       message: 'Hello! Received.',
       id: 'D255Q-132' }
] }
lastId: '1',
firstId: '1',
count: '1' }

但是,当我使用相同的ChatService类在离子角应用程序中运行脚本时,它会导致以下CORS错误。

代码语言:javascript
运行
复制
Access to fetch at 'https://chat.company.io/.well-known/host-meta' from origin 'http://localhost:8100' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

关于信息,存在并具有以下内容:

代码语言:javascript
运行
复制
<?xml version='1.0' encoding='utf-8'?>
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
  <Link rel="urn:xmpp:alt-connections:httppoll"
        href="https://chat.company.io:443" />
</XRD>

后端基础设施包括一个Nginx服务器,聊天服务器在它后面运行,具有以下开放端口: 443,7070,5222,5223。

请帮忙找出问题的所在。

EN

回答 1

Stack Overflow用户

发布于 2020-10-08 16:15:06

可能的CORS问题,启用Openfire中对CORS的支持,服务器->服务器设置-> http绑定-> CORS部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64156604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档