设置允许跨域访问

设置允许跨域访问
Nginx:
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE;
add_header Access-Control-Allow-Headers 'Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin';

PHP:
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin');

posted @ 2020-06-08 14:41  小叮当的肚兜  阅读(3226)  评论(0编辑  收藏  举报