Error: Content-Type is not allowed by Access-Control-Allow-Headers

前端 未结 6 1678
旧巷少年郎
旧巷少年郎 2020-12-23 12:20

I am getting this error in Chrome when trying to send an ajax request:

Content-Type is not allowed by Access-Control-Allow-Headers

Everythi

6条回答
  •  执念已碎
    2020-12-23 13:21

    for nginx

    location / {
        proxy_pass http://localhost:59100;
        proxy_http_version 1.1;
        # proxy_set_header Upgrade $http_upgrade;
        # proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
    
        # Simple requests
        if ($request_method ~* "(GET|POST)") {
          add_header "Access-Control-Allow-Origin"  *;
        }
    
        # Preflighted requests
        if ($request_method = OPTIONS ) {
          add_header "Access-Control-Allow-Origin"  *;
          add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
          add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
        }
    
        # proxy_cache_bypass $http_upgrade;
        # add_header Access-Control-Allow-Origin *;
        # add_header Access-Control-Allow-Headers Content-Type;
    }
    

    see https://distinctplace.com/2017/04/17/nginx-access-control-allow-origin-cors/

提交回复
热议问题