在我使用 axios 从我的网站请求的后端端点上,大多数浏览器没有在请求标头上设置“sec-fetch-mode”和“sec-fetch-site”,它们似乎工作正常。
但是,很少有浏览器设置标头sec-fetch-mode:cors
,sec-fetch-dest: empty
和sec-fetch-site:same-site
, 在这种情况下连接关闭并且浏览器控制台显示以下错误。
Access to XMLHttpRequest at 'https://site-url.xyz/endpoint1' from origin
'https://xxx.site-url.xyz' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested resource.
后端有以下配置:
response.headers.add('Access-Control-Allow-Origin', "*")
response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,OPTIONS')
response.headers.add('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
有没有办法从前端或后端的代码中控制这些标头?