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");

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注