为了测试与Openfire XMPP服务器的客户端连接,首先测试了以下测试脚本(nodejs),该脚本成功运行。
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()
输出:
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错误。
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.
关于信息,存在并具有以下内容:
<?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。
请帮忙找出问题的所在。
发布于 2020-10-08 16:15:06
可能的CORS问题,启用Openfire中对CORS的支持,服务器->服务器设置-> http绑定-> CORS部分。
https://stackoverflow.com/questions/64156604
复制相似问题