Access-Control-Allow-Origin syntax

允我心安 提交于 2020-01-12 14:14:50

问题


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');

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');

It works well for the subdomain1.from.example.com only.

What was the issue with first header?


回答1:


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.



来源:https://stackoverflow.com/questions/12744278/access-control-allow-origin-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!