header('Access-Control-Allow-Origin: *'); Not allowing CORS request

前端 未结 3 1286
醉酒成梦
醉酒成梦 2021-02-06 06:45

I have a PHP file which generates a JSON document.

I\'ve set the header as follows but am still getting an error.

header(\'Access-Control-Al         


        
3条回答
  •  北海茫月
    2021-02-06 07:24

    with htaccess file you can try to set :

    Header always set Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, PATCH,DELETE"
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Credentials "true"
    Header always set Access-Control-Allow-Headers "content-type,Authorization,Cache-Control,X-Requested-With, X-XSRF-TOKEN"
    

    or can use for php as:

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, PATCH, DELETE');
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Headers: Authorization, Content-Type, x-xsrf-token, x_csrftoken, Cache-Control, X-Requested-With');
    

提交回复
热议问题