我已经安装并配置了Prosody服务器。它监听标准的localhost:5222端口。在配置文件中添加了管理员用户1@example.com。但是每次向服务器发送请求都会出现错误:
<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="" version="1.0">
<stream:error>
<not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
</stream:error>
</stream:stream>
作为客户端,我想使用strophe.js。我只发送出席状态 ($pres)。以下是我的代码。
'use strict';
angular.module('xmppTestApp')
.controller('ChatCtrl', function () {
var vm = this;
var url = "http://localhost:5222";
var connection = null;
var output = document.getElementById("output");
function log(message) {
var line = document.createElement("div");
line.textContent = message;
output.appendChild(line);
}
function connectHandler(cond) {
if (cond == Strophe.Status.CONNECTED) {
log("connected");
connection.send($pres());
}
else {
log("not connected");
}
}
vm.connectB = function() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
console.info(url);
console.info(username);
console.info(password);
connection = new Strophe.Connection(url);
connection.connect(username, password, connectHandler);
}
});
在控制台中我看到了错误:
XMLHttpRequest cannot load http://localhost:5222/. No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:9000' is therefore not allowed access.
我该如何在请求中添加'Access-Control-Allow-Origin'头部信息?
当我尝试发送请求到 localhost:5222(不带http)时,我得到以下错误:
XMLHttpRequest cannot load localhost:5222. Cross origin requests are only supported for HTTP.
当我通过 WebSocket 发送它时,我收到的是:
WebSocket connection to 'ws://localhost:5222/' failed: Error during WebSocket handshake: Unexpected response code: 200
Fiddler为我提供了协议违规报告:
The server didn't return properly-formatted HTTP Headers. Maybe missing altogether
(e.g. HTTP/0.9), maybe only \r\r instead of \r\n\r\n?
cross-domain-bosh = true
位于配置的全局部分中。此外,请尝试在/http-bind
之后添加一个反斜杠,例如:/http-bind/
。 - fpsColtoncrossdomain.xml
应该由Prosody为您生成。我个人从未使用过Prosody,所以不确定为什么它无法正常工作。您是否尝试过重新启动所有相关的Prosody服务? - fpsColton