【发布时间】:2014-11-26 14:45:52
【问题描述】:
最后我决定发布...我觉得白痴,很多信息,我没有找到答案,
好吧,问题出在 CORS 中,我尝试在 angularJS 中执行此操作:
var request = $http({
method: "POST",
url: url,
data: data
});
url 是一个带有 symfony 执行 JsonResponse() 的服务器,没什么特别的,用 POSTMAN 尝试它一切都很好(所以.. 服务器很好?)但是当我尝试使用其他网络时,我在控制台中看到:
XMLHttpRequest cannot load http://server/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 405.
实际上在 symfony 中我有带有该配置的 NelmioBundle:
nelmio_cors:
defaults:
allow_credentials: true
allow_origin: ['*']
allow_headers: ['*']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE','OPTIONS']
max_age: 3600
paths:
'^/':
allow_origin: ['*']
allow_headers: ['*']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE','OPTIONS']
max_age: 3600
我正在使用 LEMP 获取更多信息,
感谢您的提前,抱歉我的英语很糟糕!
【问题讨论】:
-
您没有在默认值或路径中定义
host。