访问控制 - 允许 - 产地语法 [英] Access-Control-Allow-Origin syntax

查看:91
本文介绍了访问控制 - 允许 - 产地语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许所有的 from.example.com 的子域的跨域资源共享。 所以我加了跨域资源共享的头名如下图所示的页面中的 subdomain1.to.example.com 的。

I want allow Cross-origin resource sharing from all the sub-domain of from.example.com. So I added Cross-origin resource sharing header as given below to a page in subdomain1.to.example.com.

<?php header('Access-Control-Allow-Origin: *.from.example.com');

和我尝试的使用AJAX来访问该网页形式的 subdomain1.from.example.com。 我没有得到回应。所以,我只是改变了上述标题下面给出。

And I tried to access the page form subdomain1.from.example.com using ajax. I didn't get the response. So I just changed the above header as given below.

<?php header('Access-Control-Allow-Origin: http://subdomain1.from.example.com');

它运作良好,为的 subdomain1.from.example.com 的唯一。

什么是问题,第一个标题?

What was the issue with first header?

推荐答案

通配符没有在访问控制 - 允许 - 原产地允许头。它必须是精确匹配。您可以让所有域将其值设置为 * ,或有条件回声如果原产地请求头的值它符合允许的领域之一。

Wildcards are not allowed in the Access-Control-Allow-Origin header. It has to be an exact match. You can either allow all domains by setting the value to *, or conditionally echo the value of the Origin request header if it matches one of your allowed domains.

请注意,地规范允许为用空格分隔的多个来源。但是我不知道这是否与访问控制 - 允许 - 原产地头。这可能是值得一试。

Note that the Origin spec allows for multiple origins separated by a space. However I am not sure if this works with the Access-Control-Allow-Origin header. It may be worth a try.

这篇关于访问控制 - 允许 - 产地语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆