TP5 跨域

a网站访问B网站接口,B网站为TP5

可在B网站application->tags.php 文件中添加如下代码:

// 应用初始化

'app_init' => [

    'app\\api\\behavior\\CORS'

],

新建文件 application->api->behavior->CORS.php

<?php
namespace app\api\behavior;
use think\Response;
class CORS
{
    public function appInit(&$params)
    {
        header('Access-Control-Allow-Origin: *');
        header("Access-Control-Allow-Headers: token,Origin, X-Requested-With, Content-Type, Accept");
        header('Access-Control-Allow-Methods: POST,GET');
        if (request()->isOptions()) {
            exit();
        }
    }
}

 

 

 

 

 

相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页