api接口开发跨域注意事项和设置
2021-07-15 18:18
标签:注意 code access agent 跨域请求 str request get 注意事项 因为跨域请求会先发送一个OPTIONS请求,所以需要判断下OPTIONS请求的就直接返回 在返回json数据的时候需要在头部加上 api接口开发跨域注意事项和设置 标签:注意 code access agent 跨域请求 str request get 注意事项 原文地址:https://www.cnblogs.com/whlives/p/8943996.htmlif(strtoupper($_SERVER[‘REQUEST_METHOD‘])== ‘OPTIONS‘){
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Headers:content-type");
header("Access-Control-Request-Method:GET,POST");
exit;
}
header(‘Access-Control-Allow-Origin: *‘);
header(‘Access-Control-Allow-Methods: GET,POST‘);
header(‘Access-Control-Allow-Headers: Destination, Content-Type, User-Agent, X-Requested-With, If-Modified-Since‘);
header(‘Access-Control-Allow-Credentials: true‘);