在ajax上请求Neo4j失败的CORS

时间:2012-07-01 22:21:46

标签: jquery ajax neo4j cors

我正在尝试使用Backbone.js模型来访问Neo4j内容。我无法理解为什么以下通信未通过跨源检查:

首先是OPTIONS请求:

Request URL:http://localhost:7474/db/data/cypher
Request Method:OPTIONS
Status Code:204 No Content
Request Headers
  Accept:*/*
  Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:en-US,en;q=0.8
  Access-Control-Request-Headers:origin, content-type, accept
  Access-Control-Request-Method:POST
  Connection:keep-alive
  Host:localhost:7474
  Origin:http://localhost:3000
  Referer:http://localhost:3000/test/
  User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
Response Headers
  Access-Control-Allow-Headers:origin, content-type, accept
  Access-Control-Allow-Methods:POST
  Access-Control-Allow-Origin:*
  Allow:OPTIONS,POST
  Server:Jetty(6.1.25)

然后POST请求:

Request URL:http://localhost:7474/db/data/cypher
Request Headers
  Accept:application/json, text/javascript, */*; q=0.01
  Content-Type:application/json
  Origin:http://localhost:3000
  Referer:http://localhost:3000/test/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
Request Payload
  start n=node(0) match n-[:hasClass]->c where c.className=Collection return c

我收到控制台错误:

OPTIONS http://localhost:7474/db/data/cypher 204 (No Content) jquery-1.7.2.min.js:4
XMLHttpRequest cannot load http://localhost:7474/db/data/cypher. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

据我所知,应该允许该请求,因为预检请求表示Access-Control-Allow-Origin:*。有什么建议?有什么我想念的吗? 谢谢!

3 个答案:

答案 0 :(得分:1)

CORS在现已弃用的旧版Cypher HTTP端点上失败 http://neo4j.com/docs/stable/rest-api-cypher.html

新的Transactional Cypher HTTP端点上似乎没有出现此问题 http://neo4j.com/docs/stable/rest-api-transactional.html

答案 1 :(得分:0)

自从我处理跨源请求以来已经很长时间了,但可能会在某种程度上缺少标头。不过不确定。请注意,浏览器会生成不符合请求的情况,因此可能需要检查浏览器对x-origin的限制。例如,如果您使用的是file:// url。

,许多浏览器都不允许使用它

对交叉原始请求的支持不是Neo4j服务器的文档化功能,它存在遗留原因,并且出于安全原因很可能会被删除(因为没有额外的安全层,如果有数据库,您的数据库可能会被劫持攻击者知道它的URL。)

虽然可能值得将其作为默认设置允许..

答案 2 :(得分:0)

看起来您正在使用Chrome,我认为this bug可能是相关的。

Ticket #67743: Access-Control-Allow-Origin: * doesn't match localhost