我正在使用 Rails 3 开发 API-Server,到目前为止它非常方便,但我一直遇到错误,我不确定这是因为我的 Apache 设置还是 Rails 应用程序。
当我尝试通过 XHR 在http://sample.domain/uri/id上执行 HTTP DELETE 或 PUT 请求时,curl 或 HTTP-Client.app Rails 或 Apache 以 404 或 403 响应(取决于客户端。我认为是因为cors) 和 Safari 开发者控制台响应
XMLHttpRequest cannot load http://sample.domain/uri/id. Origin http://web.client/ is not allowed by Access-Control-Allow-Origin.
我在 Apache2 上使用 mod_rack aka mod_rails 并且我的虚拟主机实际上包含以下内容:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods POST,GET,DELETE,PUT,OPTIONS
Header set Access-Control-Allow-Headers X-Requested-With
Apache error_log 响应以下错误:
[Sat Oct 30 01:37:34 2010] [error] [client 22.222.222.22] client denied by server configuration: /path/to/rails/folder/public, referer: http://web.client/
Rails development.log 响应
Started OPTIONS "/uri/id" for 84.190.123.140 at 2010-10-30 03:18:42 +0200
ActionController::RoutingError (No route matches "/uri/id"):
在这里,我不确定为什么 OPTIONS 电话会出现低谷,因为我认为这只是预检,并且肯定没有 OPTIONS 路线,因为我想回复 DELETE
如果您对如何解决此问题有任何想法,请与我分享。
非常感谢大卫