有没有办法允许多个跨域使用Access-Control-Allow-Origin标头?
我知道了*,但它太开放了.我真的想只允许一些域名.
举个例子,像这样:
Access-Control-Allow-Origin: http://domain1.example, http://domain2.example
Run Code Online (Sandbox Code Playgroud)
我已经尝试过上面的代码,但它似乎不适用于Firefox.
是否可以指定多个域,或者我只坚持一个?
我有一个简单的PHP脚本,我正在尝试跨域CORS请求:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
...
Run Code Online (Sandbox Code Playgroud)
但我仍然得到错误:
X-Requested-With不允许请求标头字段Access-Control-Allow-Headers
我缺少什么?
我正在尝试制作一个简单的php后端来处理另一个服务器中的联系表单,但是尽管添加了正确的标题,它仍然给我相同的错误消息:
XMLHttpRequest cannot load https://php-contact-form-lual.herokuapp.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4000' is therefore not allowed access. The response had HTTP status code 404.
Run Code Online (Sandbox Code Playgroud)
这是ajax请求:
$.ajax({
type: 'POST',
url: 'https://php-contact-form-lual.herokuapp.com/',
data: {
subject: 'subject',
to: 'receiver',
name: $('#name').val(),
email: $('#email').val(),
msg: $('#msg').val()
}
}) // then the callbacks
Run Code Online (Sandbox Code Playgroud)
这是PHP:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
// return only the headers and not the content
// only allow CORS if we're doing a POST - i.e. no …Run Code Online (Sandbox Code Playgroud)