所以我设置了一个 ejabberd XMPP 服务器并使用 nginx 作为 EC2 实例上的代理。Strophe.js echobot 示例可以从我的 Chrome 浏览器连接。以下是请求标头:
Request URL:http://foo.eu-west-1.compute.amazonaws.com/http-bind
Request Method:POST
Status Code:200 OK
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:115
Content-Type:application/xml
Host:foo.compute.amazonaws.com
Origin:foo.eu-west-1.compute.amazonaws.com
Referer:foo.eu-west-1.compute.amazonaws.com/examples/echobot.html
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Request Payload
<body rid='2692151172' xmlns='http://jabber.org/protocol/httpbind' sid='15f6dc6cbc7a7d69b5db531c2ebf7828e094f043'/>
Response Headers
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:286
Content-Type:text/xml; charset=utf-8
Date:Fri, 04 Jan 2013 11:14:14 GMT
Server:nginx/1.2.4
我将 echobot 示例移植到 Spotify 作为应用程序。但是,Strophe 无法连接。这是 Web Inspector 网络日志:
Request URL:http://foo.eu-west-1.compute.amazonaws.com/http-bind
Request Headers
POST http://foo.eu-west-1.compute.amazonaws.com/http-bind HTTP/1.1
Origin: sp://chatify
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.15 Safari/535.11
Content-Type: application/xml
Request Payload
<body rid='790399813' xmlns='http://jabber.org/protocol/httpbind' to='ec2-54-246-45-111.eu-west-1.compute.amazonaws.com' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
现在。manifest.json 中的 RequiredPermissons 如下所示:
"RequiredPermissons": [
"http://foo.eu-west-1.compute.amazonaws.com",
"foo.eu-west-1.compute.amazonaws.com",
"http://foo.eu-west-1.compute.amazonaws.com/http-bind",
"foo.eu-west-1.compute.amazonaws.com/http-bind"
]
我可以从 foo.eu-west-1.compute.amazonaws.com 加载源代码,所以我认为这些许可有效。Spotify 应用程序使用不同的来源,“sp://chatify”。我读到这可能会导致问题。并且Access-Control-Allow-Origin:*
应该添加到标题中。我在 nginx 配置中这样做只是为了发现它一直被发送。您可以在第一个请求的响应标头中看到它。
如果打开,Strophe.js 本身会在示例的日志中说:
error 0 happened
那么有什么建议吗?清单似乎是正确的 Access-Control-Allow-Origin;* 似乎是正确的 它在浏览器中有效,但不适用于 Spotify。
谢谢你的帮助!
更新:
如果我在本地打开 echobot.html 它仍然有效。起源是那么null
。