cros

头像
卢卡
    阅读 1 分钟

    跨域请求

    跨域请求

    cbed5ad97cc79879a152bf927d86f35.png

    如何解决

    1. 接口的服务端修改响应头
      1.res.header("Access-Control-Allow-Origin","*")
      2.
    2. jsonp

      1. ajax存在的跨跨域问题
    3. Nginx配置
    add_header 'Access-Control-Allow-Methods' 'GET,OPTIONS,PUT,DELETE' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Origin' '$http_origin' always;
    add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,
                Keep-Alive,Content-Type,accept,origin,X-Requested-With' always;
    
    if ($request_method = OPTIONS ) {
        return 200;
    }

    4 Apache配置

    Header always set Access-Control-Allow-Origin "http://waffle"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
    Header always set Access-Control-Allow-Credentials "true"
    Header always set Access-Control-Allow-Headers "Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With"

    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]


    卢卡
    0 声望0 粉丝