CORS标头已在 domain1.com 上的htaccess文件中设置,允许访问 domain2.com ,但是当对domain1.com上的URL发出ajax请求时从domain2.com无法正常工作。
<IfModule mod_headers.c>
SetEnvIf Origin "http(s)?://(www\.)?(domain2.com)$" AccessControlAllowOrigin=$0$1
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Headers "Content-Type"
Header set Access-Control-Allow-Methods "GET,POST,OPTIONS"
Header set Access-Control-Allow-Credentials "true"
</IfModule>
我希望记录到控制台的成功消息,但出现此错误:
控制台中给出的错误:
Access to XMLHttpRequest at 'http://domain1.com' from origin 'http://domain2.com' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'http://domain2.coms' that is not equal to the supplied origin.
它以某种方式在标头值中添加了“ s”,我当然已经对代码进行了三遍检查,没有“ s”。