thinkphp v5.1.36 LTS 如果设置跨域访问

修改route/route.php中的路由例如

Route::get('new/:id', 'News/read')
->ext('html')
->header('Access-Control-Allow-Origin','*')//不需要token的接口不用添加
->header('Access-Control-Allow-Credentials', 'true')//不需要token的接口不用添加
->allowCrossDomain();
添加上述红色字体

 

向应用入口文件public/index.php中添加

header('Access-Control-Allow-Headers: content-type,token');

 


原文链接:https://blog.csdn.net/viva_la_free/article/details/82964395

posted @ 2020-02-26 12:55  e峰  阅读(515)  评论(0)    收藏  举报