ThinkPHP 3.2.3跨域问题
前台端分离,前端请求后端API,后端返回外链图片资源地址,报错:Access to image at '图片资源地址' from origin '前端地址' has been
blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
图片资源地址,直接在浏览器中打开可以正常显示图片
Think\Controller中加入下列代码,问题还是存在
header('Access-Control-Allow-Origin:*');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods:GET, POST, OPTIONS'); 要在图片中加入Access-Control-Allow-Origin:* 并且刷新CDN缓存即可解决,ThinkPHP 无需改动任何代码
页:
[1]