标签: 跨域

  • PHP允许跨域请求代码

    解决PHP的API跨域无法请求

    PHP代码如下:

    // 方法1.允许所有来源访问
    header("Access-Control-Allow-Origin: *");
    
    // 方法2.允许特定的请求方式
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
    
    // 方法3.允许特定的请求头
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");